use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testEnvDataWrapped.
@Issue("JENKINS-18762")
@Test
public void testEnvDataWrapped() throws Exception {
FreeStyleProject upstream = rule.createFreeStyleProject("upstream");
upstream.getBuildersList().add(new FileWriteBuilder("artifact.txt", "foobar"));
upstream.getPublishersList().add(new ArtifactArchiver("**/*", "", false, false));
FreeStyleBuild upstreamBuild = upstream.scheduleBuild2(0).get();
rule.assertBuildStatusSuccess(upstreamBuild);
FreeStyleProject downstream = rule.createFreeStyleProject();
downstream.getBuildersList().add(new WrapperBuilder(CopyArtifactUtil.createCopyArtifact("upstream", "", new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false)));
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
downstream.getBuildersList().add(envStep);
FreeStyleBuild downstreamBuild = downstream.scheduleBuild2(0).get();
rule.assertBuildStatusSuccess(downstreamBuild);
assertFile(true, "artifact.txt", downstreamBuild);
assertEquals(Integer.toString(upstreamBuild.getNumber()), envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_UPSTREAM"));
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testFilterByMetaParameters.
@Test
public void testFilterByMetaParameters() throws Exception {
FreeStyleProject other = createArtifactProject("Foo job");
other.addProperty(new ParametersDefinitionProperty(new BooleanParameterDefinition("BAR", false, "")));
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new BooleanParameterValue("BAR", false))).get());
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new BooleanParameterValue("BAR", true))).get());
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new BooleanParameterValue("BAR", false))).get());
FreeStyleProject p = createProject(other.getName(), "$VAR=true", "*.txt", "", true, false, false, true);
p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("VAR", "")));
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
p.getBuildersList().add(envStep);
FreeStyleBuild b = p.scheduleBuild2(0, new UserCause(), new ParametersAction(new StringParameterValue("VAR", "BAR"))).get();
rule.assertBuildStatusSuccess(b);
assertEquals("2", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testEnvData.
/**
* Test that info about selected builds is added into the environment for later build steps.
*/
@Test
public void testEnvData() throws Exception {
// Also test conversion of job name to env var name, only keeping letters:
FreeStyleProject other = createArtifactProject("My (Test) Job"), p = createProject(other.getName(), null, "", "", false, false, false, true);
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
p.getBuildersList().add(envStep);
// Bump up the build number a bit:
for (int i = 0; i < 3; i++) other.assignBuildNumber();
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause()).get());
FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("4", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_MY_TEST_JOB"));
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.
the class CopyArtifactTest method testFilterByParameters.
/**
* Test filtering on parameters, ie. last stable build with parameter FOO=bar.
*/
@Test
public void testFilterByParameters() throws Exception {
FreeStyleProject other = createArtifactProject("Foo job");
other.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("FOO", ""), new BooleanParameterDefinition("BAR", false, ""), new ChoiceParameterDefinition("BAZ", new String[] { "foo", "bar", "baz" }, "")));
// #1: FOO=foo BAR=false BAZ=baz
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new StringParameterValue("FOO", "foo"), new BooleanParameterValue("BAR", false), new StringParameterValue("BAZ", "baz"))).get());
// #2: FOO=bar BAR=true BAZ=foo
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new StringParameterValue("FOO", "bar"), new BooleanParameterValue("BAR", true), new StringParameterValue("BAZ", "foo"))).get());
// #3: FOO=foo BAR=true BAZ=bar
rule.assertBuildStatusSuccess(other.scheduleBuild2(0, new UserCause(), new ParametersAction(new StringParameterValue("FOO", "foo"), new BooleanParameterValue("BAR", true), new StringParameterValue("BAZ", "bar"))).get());
FreeStyleProject p = createProject(other.getName(), "FOO=bar", "*.txt", "", true, false, false, true);
CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
p.getBuildersList().add(envStep);
FreeStyleBuild b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("2", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
p = createProject(other.getName(), "BAR=false", "*.txt", "", true, false, false, true);
p.getBuildersList().add(envStep);
b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("1", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
p = createProject(other.getName(), "BAZ=foo,BAR=true", "*.txt", "", true, false, false, true);
p.getBuildersList().add(envStep);
b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("2", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
p = createProject(other.getName(), "FOO=foo,BAR=false,BAZ=baz", "*.txt", "", true, false, false, true);
p.getBuildersList().add(envStep);
b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("1", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
p = createProject(other.getName(), "BAZ=bar,FOO=bogus", "*.txt", "", true, false, false, true);
b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatus(Result.FAILURE, b);
// Test matching other build variables besides parameters
p = createProject(other.getName(), "BUILD_NUMBER=2", "*.txt", "", true, false, false, true);
p.getBuildersList().add(envStep);
b = p.scheduleBuild2(0, new UserCause()).get();
rule.assertBuildStatusSuccess(b);
assertEquals("2", envStep.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_FOO_JOB"));
// Test coverage for EnvAction
boolean ok = false;
for (Action a : b.getActions()) {
if ("hudson.plugins.copyartifact.CopyArtifact$EnvAction".equals(a.getClass().getName())) {
assertNull(a.getIconFileName());
assertNull(a.getDisplayName());
assertNull(a.getUrlName());
ok = true;
}
}
assertTrue(ok);
}
use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.
the class SimpleBuildWrapperTest method envOverride.
@Test
public void envOverride() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new WrapperWithEnvOverride());
CaptureEnvironmentBuilder captureEnvironment = new CaptureEnvironmentBuilder();
p.getBuildersList().add(captureEnvironment);
FreeStyleBuild b = r.buildAndAssertSuccess(p);
String path = captureEnvironment.getEnvVars().get("PATH");
assertTrue(path, path.startsWith(b.getWorkspace().child("bin").getRemote() + File.pathSeparatorChar));
}
Aggregations