Skip to content
Permalink
Browse files

Fixed JENKINS-11067

  • Loading branch information...
gboissinot committed Sep 27, 2011
1 parent 1a2b745 commit 1adeec115c1c960b37ccb7a3c3d9d0c53cf15adb
Showing with 36 additions and 36 deletions.
  1. +36 −36 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
@@ -49,35 +49,38 @@ public Environment setUpEnvironment(AbstractBuild build, Launcher launcher, Buil
variables.putAll(getBuildVariables(build));
}

//Build a properties object with all information
final Map<String, String> envMap = getEnvVarsFromInfoObject(info, variables, launcher, listener);
variables.putAll(envMap);

// Retrieve triggered cause
if (info.isPopulateTriggerCause()) {
Map<String, String> triggerVariable = new BuildCauseRetriever().getTriggeredCause(build);
variables.putAll(triggerVariable);
}
final FilePath rootPath = getNodeRootPath();
if (rootPath != null) {

//Resolves vars each other
EnvVars.resolve(variables);
//Build a properties object with all information
final Map<String, String> envMap = getEnvVarsFromProperties(rootPath, info, variables, launcher, listener);
variables.putAll(envMap);

//Remove unset variables
final Map<String, String> resultVariables = new EnvInjectEnvVarsUnset(logger).removeUnsetVars(variables);
// Retrieve triggered cause
if (info.isPopulateTriggerCause()) {
Map<String, String> triggerVariable = new BuildCauseRetriever().getTriggeredCause(build);
variables.putAll(triggerVariable);
}

//Add a display action
FilePath rootPath = getNodeRootPath();
if (rootPath != null) {
//Resolves vars each other
EnvVars.resolve(variables);

//Remove unset variables
final Map<String, String> resultVariables = new EnvInjectEnvVarsUnset(logger).removeUnsetVars(variables);

//Add an action
new EnvInjectActionSetter(rootPath).addEnvVarsToEnvInjectBuildAction(build, resultVariables);
}

return new Environment() {
//Execute script
executeScript(rootPath, info, resultVariables, launcher, listener);

@Override
public void buildEnvVars(Map<String, String> env) {
env.putAll(resultVariables);
}
};
return new Environment() {
@Override
public void buildEnvVars(Map<String, String> env) {
env.putAll(resultVariables);
}
};
}

} catch (EnvInjectException envEx) {
logger.error("SEVERE ERROR occurs: " + envEx.getMessage());
@@ -88,29 +91,26 @@ public void buildEnvVars(Map<String, String> env) {
}
}


return new Environment() {
};
}

private Map<String, String> getEnvVarsFromInfoObject(final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws Throwable {

private Map<String, String> getEnvVarsFromProperties(FilePath rootPath, final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
final Map<String, String> resultMap = new LinkedHashMap<String, String>();

EnvInjectLogger logger = new EnvInjectLogger(listener);
FilePath rootPath = getNodeRootPath();
if (rootPath != null) {

//Get env vars from properties
resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(info, currentEnvVars, logger)));

//Execute script info
EnvInjectScriptExecutorService scriptExecutorService = new EnvInjectScriptExecutorService(info, currentEnvVars, rootPath, launcher, logger);
scriptExecutorService.executeScriptFromInfoObject();
}

//Get env vars from properties
resultMap.putAll(rootPath.act(new PropertiesVariablesRetriever(info, currentEnvVars, logger)));
return resultMap;
}

private static void executeScript(FilePath rootPath, final EnvInjectJobPropertyInfo info, final Map<String, String> currentEnvVars, final Launcher launcher, BuildListener listener) throws EnvInjectException {
EnvInjectLogger logger = new EnvInjectLogger(listener);
EnvInjectScriptExecutorService scriptExecutorService = new EnvInjectScriptExecutorService(info, currentEnvVars, rootPath, launcher, logger);
scriptExecutorService.executeScriptFromInfoObject();
}

private Node getNode() {
Computer computer = Computer.currentComputer();
return computer.getNode();

0 comments on commit 1adeec1

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