Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Feb 16, 2012
1 parent 05a4800 commit f2b3a49
Showing 1 changed file with 30 additions and 3 deletions.
Expand Up @@ -74,8 +74,8 @@ private Environment setUpEnvironmentNonMatrixProject(AbstractBuild build, Launch
//Add Jenkins System variables
if (envInjectJobProperty.isKeepJenkinsSystemVariables()) {
logger.info("Jenkins system variables are kept.");
infraEnvVarsMaster.putAll(getJenkinsSystemVariablesMaster(build, true));
infraEnvVarsNode.putAll(getJenkinsSystemVariablesMaster(build, false));
infraEnvVarsMaster.putAll(getJenkinsSystemVariables(build, true));
infraEnvVarsNode.putAll(getJenkinsSystemVariables(build, false));
}

//Add build variables
Expand Down Expand Up @@ -151,7 +151,7 @@ private boolean isMatrixRun(AbstractBuild build) {
return build instanceof MatrixRun;
}

private Map<String, String> getJenkinsSystemVariablesMaster(AbstractBuild build, boolean onMaster) throws IOException, InterruptedException {
private Map<String, String> getJenkinsSystemVariables(AbstractBuild build, boolean onMaster) throws IOException, InterruptedException {

Map<String, String> result = new TreeMap<String, String>();

Expand All @@ -169,6 +169,11 @@ private Map<String, String> getJenkinsSystemVariablesMaster(AbstractBuild build,
if (n != null)
result.put("NODE_NAME", computer.getName());
result.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " "));

Executor e = build.getExecutor();
if (e != null) {
result.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber()));
}
}

String rootUrl = Hudson.getInstance().getRootUrl();
Expand Down Expand Up @@ -281,6 +286,9 @@ public void onCompleted(Run run, TaskListener listener) {
}
}

//Mask global passwords if any
maskGlobalPasswordsIfAny(logger, envVars);

//Add or override EnvInject Action
EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(getNodeRootPath());
try {
Expand All @@ -296,4 +304,23 @@ public void onCompleted(Run run, TaskListener listener) {
throw new Run.RunnerAbortedException();
}
}

private void maskGlobalPasswordsIfAny(EnvInjectLogger logger, Map<String, String> envVars) {
XmlFile xmlFile = EnvInjectNodeProperty.EnvInjectNodePropertyDescriptor.getConfigFile();
if (xmlFile.exists()) {
EnvInjectNodeProperty.EnvInjectNodePropertyDescriptor desc = null;
try {
desc = (EnvInjectNodeProperty.EnvInjectNodePropertyDescriptor) xmlFile.read();
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
EnvInjectGlobalPasswordEntry[] envInjectGlobalPasswordEntries = desc.getEnvInjectGlobalPasswordEntries();
for (EnvInjectGlobalPasswordEntry globalPasswordEntry : envInjectGlobalPasswordEntries) {
envVars.put(globalPasswordEntry.getName(),
globalPasswordEntry.getValue().getEncryptedValue());
}
}

}
}

0 comments on commit f2b3a49

Please sign in to comment.