Skip to content
Permalink
Browse files
[FIXED JENKINS-25226] - Resolve environment variables with a highest …
…priority

Other variables (projects, default parameters, etc.) will be used in the case of missing macros.
It should not happen in general, but may appear in buildEnvironment()

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Oct 30, 2014
1 parent 7fdf8d0 commit 7b22e0b18e27941d07269d53b63e3720841944e5
Showing with 18 additions and 14 deletions.
  1. +18 −14 src/main/java/hudson/plugins/perforce/utils/MacroStringHelper.java
@@ -250,7 +250,8 @@ private static String substituteParametersNoCheck (
}

/**
* Substitute parameters and validate contents of the resulting string
* Substitute parameters and validate contents of the resulting string.
* Environment variables have the highest priority.
* @param inputString Input string
* @param instance Instance of {@link PerforceSCM}
* @param build Related build
@@ -266,20 +267,9 @@ private static String substituteParametersNoCheck(
if (!containsMacro(inputString)) {
return inputString;
}

String string = substituteParametersNoCheck(inputString, instance,
build.getProject(), build.getBuiltOn(), env);

// Substitute default build variables
Map<String, String> substitutions = new HashMap<String, String>();
getDefaultBuildSubstitutions(build, substitutions);
String result = MacroStringHelper.substituteParametersNoCheck(string, substitutions);
result = MacroStringHelper.substituteParametersNoCheck(result, build.getBuildVariables());
if (!containsMacro(string)) {
return string;
}
String result = inputString;

// The last attempts: Try to build the full environment
// The last attempts: Try to build the full environment
Map<String, String> environmentVarsFromExtensions = new TreeMap<String, String>();
boolean useEnvironment = true;
for (StackTraceElement ste : (new Throwable()).getStackTrace()) { // Inspect the stacktrace to avoid the infinite recursion
@@ -298,7 +288,21 @@ private static String substituteParametersNoCheck(
}
}
result = MacroStringHelper.substituteParametersNoCheck(result, environmentVarsFromExtensions);

// Intermediate
if (!containsMacro(result)) {
return result;
}

// Substitute static variables
result = substituteParametersNoCheck(result, instance, build.getProject(), build.getBuiltOn(), env);

// Substitute default build variables
Map<String, String> substitutions = new HashMap<String, String>();
getDefaultBuildSubstitutions(build, substitutions);
result = MacroStringHelper.substituteParametersNoCheck(result, substitutions);
result = MacroStringHelper.substituteParametersNoCheck(result, build.getBuildVariables());

return result;
}

0 comments on commit 7b22e0b

Please sign in to comment.