Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gboissinot committed Dec 26, 2012
1 parent 0becbd3 commit 00a86cf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
Expand Up @@ -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) {
Expand All @@ -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.