Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 7b22e0b
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/main/java/hudson/plugins/perforce/utils/MacroStringHelper.java
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 7b22e0b

Please sign in to comment.