Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Feb 11, 2012
1 parent 86fe42a commit a7a11d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Expand Up @@ -87,7 +87,7 @@ private Environment setUpEnvironmentNonMatrixProject(AbstractBuild build, Launch
}

//Add build parameters (or override)
Map<String, String> parametersVariables = variableGetter.getParametersVariables(build);
Map<String, String> parametersVariables = variableGetter.overrideParametersVariablesWithSecret(build);
infraEnvVarsNode.putAll(parametersVariables);

final FilePath rootPath = getNodeRootPath();
Expand Down
Expand Up @@ -6,6 +6,7 @@
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.util.LogTaskListener;
import hudson.util.Secret;
import org.jenkinsci.lib.envinject.EnvInjectAction;
import org.jenkinsci.lib.envinject.EnvInjectException;
import org.jenkinsci.lib.envinject.EnvInjectLogger;
Expand All @@ -15,6 +16,7 @@
import org.jenkinsci.plugins.envinject.EnvInjectJobPropertyInfo;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -84,21 +86,33 @@ public Map<String, String> getBuildVariables(AbstractBuild build, EnvInjectLogge
return result;
}

public Map<String, String> getParametersVariables(AbstractBuild build) {
public Map<String, String> overrideParametersVariablesWithSecret(AbstractBuild build) {
Map<String, String> result = new HashMap<String, String>();
ParametersAction params = build.getAction(ParametersAction.class);
if (params != null) {
for (ParameterValue p : params) {
if (p instanceof PasswordParameterValue) {
String value = p.createVariableResolver(build).resolve(p.getName());
if (value != null) {
StringBuffer password = new StringBuffer();
for (int i = 1; i <= value.length(); i++) {
password.append('*');
}
result.put(p.getName(), password.toString());
try {
Field valueField = p.getClass().getDeclaredField("value");
valueField.setAccessible(true);
Object valueObject = valueField.get(p);
if (valueObject instanceof Secret) {
Secret secretValue = (Secret) valueObject;
result.put(p.getName(), secretValue.getEncryptedValue());
}
} catch (NoSuchFieldException e) {
//the field doesn't exist
//test the next param
continue;
} catch (IllegalAccessException e) {
continue;
}

/*
if (p instanceof PasswordParameterValue) {
String value = (((PasswordParameterValue) p).getValue()).getEncryptedValue();
result.put(p.getName(), value);
}
*/
}
}
return result;
Expand Down

0 comments on commit a7a11d9

Please sign in to comment.