Skip to content
Permalink
Browse files

Fix JENKINS-15658

  • Loading branch information...
gboissinot committed Nov 1, 2012
1 parent 271fe37 commit b1d9dbeaade4f04d624a76b308843a94b575b9ae
@@ -182,11 +182,21 @@ public void preCheckout(AbstractBuild build, Launcher launcher, BuildListener li
try {
//Get previous
Map<String, String> previousEnvVars = variableGetter.getEnvVarsPreviousSteps(build, envInjectLogger);

//Add workspace
FilePath ws = build.getWorkspace();
previousEnvVars.put("WORKSPACE", ws.getRemote());

//Resolve variables each other and with WORKSPACE
EnvInjectEnvVars envInjectEnvVars = new EnvInjectEnvVars(envInjectLogger);
envInjectEnvVars.resolveVars(previousEnvVars, previousEnvVars);

//Remove unused variables
Map<String, String> cleanVariables = envInjectEnvVars.removeUnsetVars(previousEnvVars);

//Set new env vars
new EnvInjectActionSetter(build.getBuiltOn().getRootPath()).addEnvVarsToEnvInjectBuildAction(build, previousEnvVars);
new EnvInjectActionSetter(build.getBuiltOn().getRootPath()).addEnvVarsToEnvInjectBuildAction(build, cleanVariables);

} catch (EnvInjectException e) {
throw new IOException(e.getMessage());
}
@@ -239,7 +249,7 @@ private Environment setUpEnvironmentJobPropertyObject(AbstractBuild build, Launc
final FilePath rootPath = getNodeRootPath();
if (rootPath != null) {

EnvInjectEnvVars envInjectEnvVarsService = new EnvInjectEnvVars(logger);
final EnvInjectEnvVars envInjectEnvVarsService = new EnvInjectEnvVars(logger);

//Execute script
int resultCode = envInjectEnvVarsService.executeScript(info.isLoadFilesFromMaster(),
@@ -261,22 +271,26 @@ private Environment setUpEnvironmentJobPropertyObject(AbstractBuild build, Launc
//Get variables get by contribution
Map<String, String> contributionVariables = getEnvVarsByContribution(build, envInjectJobProperty, logger, listener);

final Map<String, String> resultVariables = envInjectEnvVarsService.getMergedVariables(
final Map<String, String> mergedVariables = envInjectEnvVarsService.getMergedVariables(
infraEnvVarsNode,
propertiesVariables,
groovyMapEnvVars,
contributionVariables);

//Add an action
new EnvInjectActionSetter(rootPath).addEnvVarsToEnvInjectBuildAction(build, resultVariables);
//Add an action to share injected environment variables
new EnvInjectActionSetter(rootPath).addEnvVarsToEnvInjectBuildAction(build, mergedVariables);

//Add a wrapper to intercept the preCheckout event and add specific variables such as WORKSPACE variable
BuildWrapperService wrapperService = new BuildWrapperService();
wrapperService.addBuildWrapper(build, new JobSetupEnvironmentWrapper());


return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {
env.putAll(resultVariables);
envInjectEnvVarsService.resolveVars(mergedVariables, mergedVariables); //resolve variables each other
//however, here preCheckout of EnvBuildWrapper is not yet performed
env.putAll(mergedVariables);
}
};
}
@@ -162,8 +162,7 @@ public int executeScript(
variables.putAll(contribEnvVars);
variables.putAll(propertiesEnvVars);

//4-- Remove unset variables
return removeUnsetVars(variables);
return variables;
}


@@ -195,7 +194,7 @@ public void resolveVars(Map<String, String> variables, Map<String, String> env)
}
}

private Map<String, String> removeUnsetVars(Map<String, String> envVars) {
public Map<String, String> removeUnsetVars(Map<String, String> envVars) {
Map<String, String> result = new HashMap<String, String>();
for (Map.Entry<String, String> entry : envVars.entrySet()) {

0 comments on commit b1d9dbe

Please sign in to comment.
You can’t perform that action at this time.