Skip to content
Permalink
Browse files

Fix JENKINS-12788

  • Loading branch information...
gboissinot committed Feb 16, 2012
1 parent 05a4800 commit f2b3a4921b5127718214ad0454bb55a3812dbcfb
Showing with 30 additions and 3 deletions.
  1. +30 −3 src/main/java/org/jenkinsci/plugins/envinject/EnvInjectListener.java
@@ -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
@@ -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>();

@@ -169,6 +169,11 @@ private boolean isMatrixRun(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();
@@ -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 {
@@ -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.
You can’t perform that action at this time.