Skip to content
Permalink
Browse files

Fix JENKINS-16016

  • Loading branch information...
gboissinot committed Dec 26, 2012
1 parent 0becbd3 commit 00a86cfc413b4f9b3b26eb8d2bade66d8d3d3941
@@ -367,9 +367,13 @@ public void onCompleted(Run run, TaskListener listener) {
return;
}

//Mask passwords
EnvVars envVars = new EnvVars();
EnvInjectLogger logger = new EnvInjectLogger(listener);
EnvInjectPasswordsMasker passwordsMasker = new EnvInjectPasswordsMasker();
passwordsMasker.maskPasswordsIfAny(build, logger, envVars);

if (!(build instanceof MatrixBuild)) {
EnvVars envVars = new EnvVars();
EnvInjectLogger logger = new EnvInjectLogger(listener);

EnvInjectPluginAction envInjectAction = run.getAction(EnvInjectPluginAction.class);
if (envInjectAction != null) {
@@ -393,26 +397,23 @@ public void onCompleted(Run run, TaskListener listener) {
throw new Run.RunnerAbortedException();
}
}
}

//Mask passwords
EnvInjectPasswordsMasker passwordsMasker = new EnvInjectPasswordsMasker();
passwordsMasker.maskPasswordsIfAny(build, logger, envVars);

//Add or override EnvInject Action
EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(getNodeRootPath());
try {
envInjectActionSetter.addEnvVarsToEnvInjectBuildAction((AbstractBuild<?, ?>) run, envVars);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (InterruptedException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}
//Add or override EnvInject Action
EnvInjectActionSetter envInjectActionSetter = new EnvInjectActionSetter(getNodeRootPath());
try {
envInjectActionSetter.addEnvVarsToEnvInjectBuildAction((AbstractBuild<?, ?>) run, envVars);
} catch (EnvInjectException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (IOException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
} catch (InterruptedException e) {
logger.error("SEVERE ERROR occurs: " + e.getMessage());
throw new Run.RunnerAbortedException();
}

}

}
@@ -0,0 +1,46 @@
package org.jenkinsci.plugins.envinject;

import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.model.Result;
import hudson.util.Secret;
import junit.framework.Assert;
import org.jvnet.hudson.test.HudsonTestCase;

import java.util.Map;

/**
* @author Gregory Boissinot
*/
public class EnvInjectPasswordMatrixProjectTest extends HudsonTestCase {

private static final String PWD_KEY = "PASS_KEY";
private static final String PWD_VALUE = "PASS_VALUE";

private MatrixProject project;

@Override
public void setUp() throws Exception {
super.setUp();
project = createMatrixProject();
}

public void testEnvInjectPasswordWrapper() throws Exception {

EnvInjectPasswordWrapper passwordWrapper = new EnvInjectPasswordWrapper();
passwordWrapper.setPasswordEntries(new EnvInjectPasswordEntry[]{
new EnvInjectPasswordEntry(PWD_KEY, PWD_VALUE)
});

project.getBuildWrappersList().add(passwordWrapper);
MatrixBuild matrixBuild = project.scheduleBuild2(0).get();
Assert.assertEquals(Result.SUCCESS, matrixBuild.getResult());

org.jenkinsci.lib.envinject.EnvInjectAction action = matrixBuild.getAction(org.jenkinsci.lib.envinject.EnvInjectAction.class);
Map<String, String> envVars = action.getEnvMap();
//The value must be encrypted in the envVars
Assert.assertEquals(Secret.fromString(PWD_VALUE).getEncryptedValue(), envVars.get(PWD_KEY));

}

}

0 comments on commit 00a86cf

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