Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Nov 1, 2012
1 parent 271fe37 commit b1d9dbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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);
}
};
}
Expand Down
Expand Up @@ -162,8 +162,7 @@ public Map<String, String> getMergedVariables(Map<String, String> infraEnvVars,
variables.putAll(contribEnvVars);
variables.putAll(propertiesEnvVars);

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


Expand Down Expand Up @@ -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()) {

Expand Down

0 comments on commit b1d9dbe

Please sign in to comment.