Search in sources :

Example 1 with TextFinderPublisher

use of org.jenkinsci.test.acceptance.plugins.textfinder.TextFinderPublisher 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)

Aggregations

ArrayList (java.util.ArrayList)1 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 NodeParameter (org.jenkinsci.test.acceptance.plugins.nodelabelparameter.NodeParameter)1 TextFinderPublisher (org.jenkinsci.test.acceptance.plugins.textfinder.TextFinderPublisher)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Issue (org.jvnet.hudson.test.Issue)1