Search in sources :

Example 51 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class NodeLabelParameterPluginTest method trigger_if_succeeds_with_failed_post_build_step.

/**
 * This test is intended to verify that the second build is not started when the
 * build already failed on the first slave in combination with the
 * "run next build only if build succeeds" setting of the node parameter.
 * <p/>
 * As a build can fail in different stages this test simulates a FAILED result
 * during the post build step. Therefore the text-finder plugin is used to
 * fail the build based on a simple pattern matching with a text file copied to
 * the slave's workspace.
 * <p/>
 * Note that in this case the main build action is still completed with status SUCCESS.
 */
@Test
@WithPlugins("text-finder")
@Issue("JENKINS-23129")
@Ignore("Until JENKINS-23129 is fixed")
public void trigger_if_succeeds_with_failed_post_build_step() throws Exception {
    FreeStyleJob j = jenkins.jobs.create();
    ArrayList<Node> slaves = new ArrayList<>();
    slaves.add(slave.install(jenkins).get());
    slaves.add(slave.install(jenkins).get());
    j.configure();
    // set up the node parameter
    NodeParameter p = j.addParameter(NodeParameter.class);
    p.setName("slavename");
    p.runIfSuccess.check();
    // copy the file to mark the status
    j.copyResource(resource("/textfinder_plugin/textfinder-result_failed.log"));
    // set up the post build action
    TextFinderPublisher tf = j.addPublisher(TextFinderPublisher.class);
    tf.filePath.sendKeys("textfinder-result_failed.log");
    tf.regEx.sendKeys("^RESULT=SUCCESS$");
    tf.succeedIfFound.click();
    j.save();
    // select both slaves for this build
    j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
    // verify failed result prevents the job to be built on further nodes.
    // As the nodes get random names and the selected nodes are utilized in alphabetical order
    // of their names, the first build will not necessarily be done on s1. Thus, it can only
    // be verified that the job has been built on one of the slaves.
    j.startBuild(singletonMap("slavename", slaves.get(0).getName() + "," + slaves.get(1).getName())).shouldFail();
    assertThat(j.getNextBuildNumber(), is(2));
}
Also used : TextFinderPublisher(org.jenkinsci.test.acceptance.plugins.textfinder.TextFinderPublisher) NodeParameter(org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 52 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class PrioritySorterPluginTest method saving_global_config_should_not_create_job_change.

// Reproduce regression fixed in https://github.com/jenkinsci/priority-sorter-plugin/commit/e46b2b1fbc4396f441c69692eb328fb982325572
@Test
@WithPlugins("jobConfigHistory")
public void saving_global_config_should_not_create_job_change() {
    FreeStyleJob job = jenkins.jobs.create();
    job.save();
    JobConfigHistory action = job.action(JobConfigHistory.class);
    final int expected = action.getChanges().size();
    final JenkinsConfig global = jenkins.getConfigPage();
    global.configure();
    global.numExecutors.set(42);
    global.save();
    assertThat(action.getChanges().size(), equalTo(expected));
}
Also used : JobConfigHistory(org.jenkinsci.test.acceptance.plugins.job_config_history.JobConfigHistory) JenkinsConfig(org.jenkinsci.test.acceptance.po.JenkinsConfig) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 53 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_create_job.

@Test
@WithPlugins({ "sidebar-link", "build-name-setter", "envinject" })
public void should_create_job() {
    // Arrange
    String jobName = "MyJob";
    String jobDescription = "My sample description";
    String jobDisplayName = "My job display name";
    String jobLabel = "!ubuntu";
    String linkUrl = "https://jenkins.io";
    String linkLabel = "jenkins.io";
    String jobDslScript = String.format(multiline("job('%s') {", "    description('%s');", "    displayName('%s');", "    label('%s');", "    customWorkspace('/tmp/custom-workspace')", "    environmentVariables(varname: 'varval')", "    properties {", "        sidebarLinks {", "            link('%s', '%s')", "        }", "    };", "    wrappers { buildName('custom-name') }", "    concurrentBuild();", "    steps {", "        shell('sleep 10')", "    }", "}"), jobName, jobDescription, jobDisplayName, jobLabel, linkUrl, linkLabel);
    Job seed = createSeedJobWithJobDsl(jobDslScript);
    seed.startBuild().shouldSucceed();
    // Verify configuration
    Job job = jenkins.jobs.get(Job.class, jobName);
    job.open();
    assertThat(job.getDescription(), containsString(jobDescription));
    assertThat(job.getDisplayName(), containsString(jobDisplayName));
    assertThat(driver, hasElement(by.href(linkUrl)));
    job.configure();
    WebElement labelElement = driver.findElement(By.xpath("//input[@name='_.label']"));
    assertEquals(jobLabel, labelElement.getAttribute("value"));
    Build build = job.scheduleBuild().waitUntilStarted();
    {
        // Verify concurrent build
        Build secondBuild = job.scheduleBuild().waitUntilStarted();
        assertTrue(build.isInProgress());
        assertTrue(secondBuild.isInProgress());
        build.stop();
        secondBuild.stop();
        build.waitUntilFinished();
        secondBuild.waitUntilFinished();
    }
    build.open();
    assertThat(build.getDisplayName(), containsString("custom-name"));
    build.open();
    driver.findElement(By.partialLinkText("Environment Variables")).click();
    assertThat(driver, hasElement(by.xpath(String.format("//tr/td[contains(text(), '%s')]", "varname"))));
    assertThat(build.getConsole(), containsString("/tmp/custom-workspace"));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) WebElement(org.openqa.selenium.WebElement) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 54 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method job_filters_include_failed_jobs_built_at_least_once.

/**
 * This test creates 3 jobs and builds 3 of them immediately. One of the fails. A list view is created with its job filter set to only
 * include jobs that failed.
 */
@Test
@WithPlugins("view-job-filters")
public void job_filters_include_failed_jobs_built_at_least_once() {
    List<Job> jobs = createAmountOfJobs(2, true);
    Job job3 = createJobThatFails();
    String jobDslScript = "listView('" + LIST_VIEW_NAME + "') {\n" + "  columns {\n" + "    name()\n" + "  }\n" + "  jobFilters {\n" + "    buildTrend {\n" + "      matchType(MatchType.INCLUDE_MATCHED)\n" + "      buildCountType(BuildCountType.AT_LEAST_ONE)\n" + "      status(BuildStatusType.FAILED)\n" + "    }\n" + "  }\n" + "}";
    View view = openNewlyCreatedListView(jobDslScript, LIST_VIEW_NAME);
    assertThat(view, not(containsJob(jobs.get(0))));
    assertThat(view, not(containsJob(jobs.get(1))));
    assertThat(view, containsJob(job3));
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Job(org.jenkinsci.test.acceptance.po.Job) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) ListView(org.jenkinsci.test.acceptance.po.ListView) View(org.jenkinsci.test.acceptance.po.View) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Example 55 with WithPlugins

use of org.jenkinsci.test.acceptance.junit.WithPlugins in project acceptance-test-harness by jenkinsci.

the class JobDslPluginTest method should_use_script_approval.

/**
 * Verifies that if script security for Job DSL scripts is enabled,
 * scripts saved by non administrators that not run in a Groovy sandbox
 * wont be executed.
 * Administrators can approve scripts in the 'Script Approval' of the
 * 'Manage Jenkins' area. Approved scripts can be executed.
 */
@Test
@WithPlugins({ "matrix-auth@2.3", "mock-security-realm" })
public void should_use_script_approval() {
    setUpSecurity();
    jenkins.login().doLogin(USER);
    FreeStyleJob seedJob = createSeedJob();
    JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
    jobDsl.setScript("job('New_Job')");
    jobDsl.setUseSandbox(false);
    seedJob.save();
    // Build should fail because script is saved from non administrator an not yet approved
    Build build = seedJob.scheduleBuild().shouldFail();
    assertThat(build.getConsole(), containsString("script not yet approved for use"));
    jenkins.logout();
    jenkins.login().doLogin(ADMIN);
    // Build should fail because script is saved from non administrator an not yet approved
    Build build2 = seedJob.scheduleBuild().shouldFail();
    assertThat(build2.getConsole(), containsString("script not yet approved for use"));
    ScriptApproval sa = new ScriptApproval(jenkins);
    sa.open();
    sa.find(seedJob.name).approve();
    jenkins.logout();
    jenkins.login().doLogin(USER);
    // Build should succeed because script is approved now
    seedJob.scheduleBuild().shouldSucceed();
}
Also used : JobDslBuildStep(org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep) Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) ScriptApproval(org.jenkinsci.test.acceptance.plugins.script_security.ScriptApproval) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)89 Test (org.junit.Test)89 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)71 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)53 Build (org.jenkinsci.test.acceptance.po.Build)39 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)31 Issue (org.jvnet.hudson.test.Issue)25 Job (org.jenkinsci.test.acceptance.po.Job)19 WithDocker (org.jenkinsci.test.acceptance.junit.WithDocker)15 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)15 ListView (org.jenkinsci.test.acceptance.po.ListView)13 View (org.jenkinsci.test.acceptance.po.View)13 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)12 WithCredentials (org.jenkinsci.test.acceptance.junit.WithCredentials)11 JobDslBuildStep (org.jenkinsci.test.acceptance.plugins.job_dsl.JobDslBuildStep)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 GlobalSecurityConfig (org.jenkinsci.test.acceptance.po.GlobalSecurityConfig)9 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)8 Ignore (org.junit.Ignore)8 WarningsAction (org.jenkinsci.test.acceptance.plugins.warnings.WarningsAction)5