Search in sources :

Example 1 with CaptureEnvironmentBuilder

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"));
}
Also used : WrapperBuilder(hudson.plugins.copyartifact.testutils.WrapperBuilder) ArtifactArchiver(hudson.tasks.ArtifactArchiver) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 2 with CaptureEnvironmentBuilder

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"));
}
Also used : UserCause(hudson.model.Cause.UserCause) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 3 with CaptureEnvironmentBuilder

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"));
}
Also used : UserCause(hudson.model.Cause.UserCause) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 4 with CaptureEnvironmentBuilder

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);
}
Also used : UserCause(hudson.model.Cause.UserCause) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 5 with CaptureEnvironmentBuilder

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));
}
Also used : FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Aggregations

CaptureEnvironmentBuilder (org.jvnet.hudson.test.CaptureEnvironmentBuilder)19 Test (org.junit.Test)17 FreeStyleProject (hudson.model.FreeStyleProject)5 HtmlForm (com.gargoylesoftware.htmlunit.html.HtmlForm)3 UserCause (hudson.model.Cause.UserCause)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Issue (org.jvnet.hudson.test.Issue)3 WebClient (org.jvnet.hudson.test.JenkinsRule.WebClient)3 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)2 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)2 FileWriteBuilder (hudson.plugins.copyartifact.testutils.FileWriteBuilder)2 ArtifactArchiver (hudson.tasks.ArtifactArchiver)2 WebClientOptions (com.gargoylesoftware.htmlunit.WebClientOptions)1 WebRequest (com.gargoylesoftware.htmlunit.WebRequest)1 HtmlCheckBoxInput (com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput)1 HtmlOption (com.gargoylesoftware.htmlunit.html.HtmlOption)1 HtmlSelect (com.gargoylesoftware.htmlunit.html.HtmlSelect)1 HtmlTextInput (com.gargoylesoftware.htmlunit.html.HtmlTextInput)1