Search in sources :

Example 16 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project jenkins by jenkinsci.

the class BuildCommandTest method executorsAliveOnParameterWithNullDefaultValue.

@Issue("JENKINS-15094")
@Test
public void executorsAliveOnParameterWithNullDefaultValue() throws Exception {
    DumbSlave slave = j.createSlave();
    FreeStyleProject project = j.createFreeStyleProject("foo");
    project.setAssignedNode(slave);
    // Create test parameter with Null default value
    NullDefaultValueParameterDefinition nullDefaultDefinition = new NullDefaultValueParameterDefinition();
    ParametersDefinitionProperty pdp = new ParametersDefinitionProperty(new StringParameterDefinition("string", "defaultValue", "description"), nullDefaultDefinition);
    project.addProperty(pdp);
    CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
    project.getBuildersList().add(builder);
    // Warmup
    j.buildAndAssertSuccess(project);
    for (Executor exec : slave.toComputer().getExecutors()) {
        assertTrue("Executor has died before the test start: " + exec, exec.isActive());
    }
    // Create CLI & run command
    CLICommandInvoker invoker = new CLICommandInvoker(j, new BuildCommand());
    CLICommandInvoker.Result result = invoker.invokeWithArgs("foo", "-p", "string=value");
    assertThat(result, failedWith(2));
    assertThat(result.stderr(), containsString("ERROR: No default value for the parameter 'FOO'."));
    // Give the job 5 seconds to be submitted
    Thread.sleep(5000);
    assertNull("Build should not be scheduled", j.jenkins.getQueue().getItem(project));
    assertNull("Build should not be scheduled", project.getBuildByNumber(2));
    // Check executors health after a timeout
    for (Executor exec : slave.toComputer().getExecutors()) {
        assertTrue("Executor is dead: " + exec, exec.isActive());
    }
}
Also used : StringParameterDefinition(hudson.model.StringParameterDefinition) Executor(hudson.model.Executor) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) DumbSlave(hudson.slaves.DumbSlave) FreeStyleProject(hudson.model.FreeStyleProject) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Issue(org.jvnet.hudson.test.Issue) SmokeTest(org.jvnet.hudson.test.SmokeTest) Test(org.junit.Test)

Example 17 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.

the class CopyArtifactTest method testEnvDataInMavenProject.

@Issue("JENKINS-16028")
@Test
public void testEnvDataInMavenProject() 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);
    MavenModuleSet downstream = setupMavenJob();
    downstream.getPrebuilders().add(CopyArtifactUtil.createCopyArtifact("upstream", "", new SpecificBuildSelector(Integer.toString(upstreamBuild.getNumber())), "**/*", "", "", false, false, false));
    CaptureEnvironmentBuilder envStep = new CaptureEnvironmentBuilder();
    downstream.getPrebuilders().add(envStep);
    MavenModuleSetBuild 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 : MavenModuleSetBuild(hudson.maven.MavenModuleSetBuild) ArtifactArchiver(hudson.tasks.ArtifactArchiver) FileWriteBuilder(hudson.plugins.copyartifact.testutils.FileWriteBuilder) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) MavenModuleSet(hudson.maven.MavenModuleSet) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 18 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.

the class CopyArtifactTest method testResultVariableSuffix.

@Test
public void testResultVariableSuffix() throws Exception {
    FreeStyleProject srcProject = createArtifactProject("SRC-PROJECT1");
    FreeStyleBuild srcBuild = srcProject.scheduleBuild2(0).get();
    rule.assertBuildStatusSuccess(srcBuild);
    // if no result variable suffix is provided
    // the default suffix (SRC_PROJECT) is used.
    {
        FreeStyleProject p = rule.createFreeStyleProject();
        p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
        null, new PermalinkBuildSelector("lastStableBuild"), // filter
        "*.txt", // excludes
        "", // target
        "", // flatten
        false, // optional
        false, // fingerprintArtifacts
        true, // resultVariableSuffix
        ""));
        CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
        p.getBuildersList().add(ceb);
        rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
        assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
    }
    // if result variable suffix is provided
    // it is used for the variable name to store.
    {
        FreeStyleProject p = rule.createFreeStyleProject();
        p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
        null, new PermalinkBuildSelector("lastStableBuild"), // filter
        "*.txt", // excludes
        "", // target
        "", // flatten
        false, // optional
        false, // fingerprintArtifacts
        true, // resultVariableSuffix
        "DEST1"));
        CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
        p.getBuildersList().add(ceb);
        rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
        assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_DEST1"));
        assertNull(ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
    }
    // if result variable suffix is invalid,
    // the default suffix (SRC_PROJECT) is used.
    {
        FreeStyleProject p = rule.createFreeStyleProject();
        p.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(srcProject.getFullName(), // parameters
        null, new PermalinkBuildSelector("lastStableBuild"), // filter
        "*.txt", // excludes
        "", // target
        "", // flatten
        false, // optional
        false, // fingerprintArtifacts
        true, // resultVariableSuffix
        "= =!?"));
        CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
        p.getBuildersList().add(ceb);
        rule.assertBuildStatusSuccess(p.scheduleBuild2(0));
        assertEquals(Integer.toString(srcBuild.getNumber()), ceb.getEnvVars().get("COPYARTIFACT_BUILD_NUMBER_SRC_PROJECT_"));
    }
}
Also used : CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) Test(org.junit.Test)

Example 19 with CaptureEnvironmentBuilder

use of org.jvnet.hudson.test.CaptureEnvironmentBuilder in project copyartifact-plugin by jenkinsci.

the class BuildSelectorParameterTest method testParameter.

/**
 * Verify BuildSelectorParameter works via HTML form, http POST and CLI.
 */
@Test
public void testParameter() throws Exception {
    FreeStyleProject job = rule.createFreeStyleProject();
    job.addProperty(new ParametersDefinitionProperty(new BuildSelectorParameter("SELECTOR", new StatusBuildSelector(false), "foo")));
    CaptureEnvironmentBuilder ceb = new CaptureEnvironmentBuilder();
    job.getBuildersList().add(ceb);
    // Run via UI (HTML form)
    WebClient wc = rule.createWebClient();
    WebClientOptions wco = wc.getOptions();
    // Jenkins sends 405 response for GET of build page.. deal with that:
    wco.setThrowExceptionOnFailingStatusCode(false);
    wco.setPrintContentOnFailingStatusCode(false);
    HtmlForm form = wc.getPage(job, "build").getFormByName("parameters");
    form.getSelectByName("").getOptionByText("Specific build").setSelected(true);
    wc.waitForBackgroundJavaScript(10000);
    form.getInputByName("_.buildNumber").setValueAttribute("6");
    rule.submit(form);
    rule.waitUntilNoActivity();
    assertEquals("<SpecificBuildSelector><buildNumber>6</buildNumber></SpecificBuildSelector>", ceb.getEnvVars().get("SELECTOR").replaceAll("\\s+", ""));
    job.getBuildersList().replace(ceb = new CaptureEnvironmentBuilder());
    // Run via HTTP POST (buildWithParameters)
    WebRequest post = new WebRequest(new URL(rule.getURL(), job.getUrl() + "/buildWithParameters"), HttpMethod.POST);
    wc.addCrumb(post);
    String xml = "<StatusBuildSelector><stable>true</stable></StatusBuildSelector>";
    post.setRequestParameters(Arrays.asList(new NameValuePair("SELECTOR", xml), post.getRequestParameters().get(0)));
    wc.getPage(post);
    rule.waitUntilNoActivity();
    assertEquals(xml, ceb.getEnvVars().get("SELECTOR"));
    job.getBuildersList().replace(ceb = new CaptureEnvironmentBuilder());
    // Run via CLI
    assertThat(new CLICommandInvoker(rule, "build").invokeWithArgs(job.getFullName(), "-p", "SELECTOR=<SavedBuildSelector/>"), CLICommandInvoker.Matcher.succeeded());
    rule.waitUntilNoActivity();
    assertEquals("<SavedBuildSelector/>", ceb.getEnvVars().get("SELECTOR"));
}
Also used : NameValuePair(com.gargoylesoftware.htmlunit.util.NameValuePair) WebClientOptions(com.gargoylesoftware.htmlunit.WebClientOptions) FreeStyleProject(hudson.model.FreeStyleProject) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) URL(java.net.URL) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) CaptureEnvironmentBuilder(org.jvnet.hudson.test.CaptureEnvironmentBuilder) CLICommandInvoker(hudson.cli.CLICommandInvoker) 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