Package org.jenkinsci.plugins.workflow.job

Examples of org.jenkinsci.plugins.workflow.job.WorkflowJob$DescriptorImpl


     * Try out a parameter.
     */
    @Test
    public void parameter() throws Exception {
        // job setup
        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
                "echo('before');",
                "def x = input message:'Do you want chocolate?', id:'Icecream', ok: 'Purchase icecream', parameters: [new BooleanParameterDefinition('chocolate',false,'Favorite icecream flavor')];",
                "echo(\"after: ${x}\");"),"\n")));


        // get the build going, and wait until workflow pauses
        QueueTaskFuture<WorkflowRun> q = foo.scheduleBuild2(0);
        WorkflowRun b = q.getStartCondition().get();
        CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();

        while (b.getAction(InputAction.class)==null) {
            e.waitForSuspension();
View Full Code Here


public class DSLTest {
   
    @Rule public JenkinsRule r = new JenkinsRule();

    @Test public void overrideFunction() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("echo 'this came from a step'"));
        r.assertLogContains("this came from a step", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
        p.setDefinition(new CpsFlowDefinition("def echo(s) {println s.toUpperCase()}\necho 'this came from my own function'\nsteps.echo 'but this is still from a step'"));
        WorkflowRun b2 = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        r.assertLogContains("THIS CAME FROM MY OWN FUNCTION", b2);
        r.assertLogContains("but this is still from a step", b2);
    }
View Full Code Here

        r.assertLogContains("THIS CAME FROM MY OWN FUNCTION", b2);
        r.assertLogContains("but this is still from a step", b2);
    }

    @Test public void flattenGString() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("def x = 'the message'; echo \"What is ${x}?\""));
        r.assertLogContains("What is the message?", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
        // TODO test structured values using @DataBoundConstructor/@DataBoundSetter via AbstractStepDescriptorImpl.instantiate (probably need a dedicated test step for that)
    }
View Full Code Here

public class PushdStepTest {

    @Rule public JenkinsRule r = new JenkinsRule();

    @Test public void basics() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");;
        p.setDefinition(new CpsFlowDefinition("node {dir('subdir') {sh 'pwd'}}"));
        r.assertLogContains("/subdir", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    }
View Full Code Here

public class ReadWriteFileStepTest {

    @Rule public JenkinsRule r = new JenkinsRule();

    @Test public void basics() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("node {sh 'echo hello > f1'; def text = readFile 'f1'; text = text.toUpperCase(); writeFile file: 'f2', text: text; sh 'cat f2'}"));
        r.assertLogContains("HELLO", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    }
View Full Code Here

        //                    B/1   B/2   B/3 ^ X/1    X/2
        //                                (restart)
        // (above are the semaphores we must signal)
        story.addStep(new Statement() {
            @Override public void evaluate() throws Throwable {
                WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "demo");
                p.setDefinition(new CpsFlowDefinition(
                        "stage(name: 'A', concurrency: 2);\n" +
                        "echo('in A');\n" +
                        "semaphore('B');\n" +
                        "stage(name: 'B', concurrency: 1);\n" +
                        "echo('in B');\n" +
                        "semaphore('X');\n" +
                        "echo('done')"));
                WorkflowRun b1 = p.scheduleBuild2(0).waitForStart();
                CpsFlowExecution e1 = (CpsFlowExecution) b1.getExecutionPromise().get();
                e1.waitForSuspension();
                assertTrue(JenkinsRule.getLog(b1), b1.isBuilding());
                WorkflowRun b2 = p.scheduleBuild2(0).waitForStart();
                CpsFlowExecution e2 = (CpsFlowExecution) b2.getExecutionPromise().get();
                e2.waitForSuspension();
                assertTrue(b2.isBuilding());
                WorkflowRun b3 = p.scheduleBuild2(0).waitForStart();
                CpsFlowExecution e3 = (CpsFlowExecution) b3.getExecutionPromise().get();
                e3.waitForSuspension();
                assertTrue(b3.isBuilding());
                try {
                    story.j.assertLogContains("in A", b1);
                    story.j.assertLogNotContains("in B", b1);
                    story.j.assertLogContains("in A", b2);
                    story.j.assertLogNotContains("in B", b2);
                    story.j.assertLogNotContains("in A", b3);
                    SemaphoreStep.success("B/1", null);
                    e1.waitForSuspension();
                    assertTrue(b1.isBuilding());
                    e2.waitForSuspension();
                    assertTrue(b2.isBuilding());
                    e3.waitForSuspension();
                    assertTrue(b3.isBuilding());
                    story.j.assertLogContains("in B", b1);
                    story.j.assertLogNotContains("done", b1);
                    story.j.assertLogNotContains("in B", b2);
                    story.j.assertLogContains("in A", b3);
                    story.j.assertLogNotContains("in B", b3);
                    SemaphoreStep.success("B/2", null);
                    e1.waitForSuspension();
                    assertTrue(b1.isBuilding());
                    e2.waitForSuspension();
                    assertTrue(b2.isBuilding());
                    e3.waitForSuspension();
                    assertTrue(b3.isBuilding());
                    story.j.assertLogNotContains("done", b1);
                    story.j.assertLogNotContains("in B", b2);
                    story.j.assertLogNotContains("in B", b3);
                    SemaphoreStep.success("B/3", null);
                    e1.waitForSuspension();
                    assertTrue(b1.isBuilding());
                    e2.waitForSuspension();
                    e3.waitForSuspension();
                    Thread.sleep(1000); // TODO why is this necessary?
                    assertFalse(b2.isBuilding());
                    assertEquals(Result.NOT_BUILT, b2.getResult());
                    InterruptedBuildAction iba = b2.getAction(InterruptedBuildAction.class);
                    assertNotNull(iba);
                    List<CauseOfInterruption> causes = iba.getCauses();
                    assertEquals(1, causes.size());
                    assertEquals(StageStepExecution.CanceledCause.class, causes.get(0).getClass());
                    assertEquals(b3, ((StageStepExecution.CanceledCause) causes.get(0)).getNewerBuild());
                    assertTrue(b3.isBuilding());
                    story.j.assertLogNotContains("done", b1);
                    story.j.assertLogNotContains("in B", b2);
                    story.j.assertLogNotContains("in B", b3);
                } finally {
                    System.out.println(JenkinsRule.getLog(b1));
                    System.out.println(JenkinsRule.getLog(b2));
                    System.out.println(JenkinsRule.getLog(b3));
                }
            }
        });
        story.addStep(new Statement() {
            @Override public void evaluate() throws Throwable {
                StageStepExecution.clear();
                WorkflowJob p = story.j.jenkins.getItemByFullName("demo", WorkflowJob.class);
                WorkflowRun b1 = p.getBuildByNumber(1);
                WorkflowRun b3 = p.getBuildByNumber(3);
                try {
                    assertTrue(b1.isBuilding());
                    story.j.assertLogNotContains("done", b1);
                    CpsFlowExecution e1 = (CpsFlowExecution) b1.getExecutionPromise().get();
                    e1.waitForSuspension();
View Full Code Here

public class CoreStepTest {

    @Rule public JenkinsRule r = new JenkinsRule();

    @Test public void artifactArchiver() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("node {sh 'touch x.txt'; step([$class: 'ArtifactArchiver', artifacts: 'x.txt', fingerprint: true])}"));
        WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        List<WorkflowRun.Artifact> artifacts = b.getArtifacts();
        assertEquals(1, artifacts.size());
        assertEquals("x.txt", artifacts.get(0).relativePath);
        Fingerprinter.FingerprintAction fa = b.getAction(Fingerprinter.FingerprintAction.class);
        assertNotNull(fa);
View Full Code Here

        assertNotNull(fa);
        assertEquals("[x.txt]", fa.getRecords().keySet().toString());
    }

    @Test public void fingerprinter() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("node {sh 'touch x.txt'; step([$class: 'Fingerprinter', targets: 'x.txt'])}"));
        WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        Fingerprinter.FingerprintAction fa = b.getAction(Fingerprinter.FingerprintAction.class);
        assertNotNull(fa);
        assertEquals("[x.txt]", fa.getRecords().keySet().toString());
    }
View Full Code Here

        assertNotNull(fa);
        assertEquals("[x.txt]", fa.getRecords().keySet().toString());
    }

    @Test public void junitResultArchiver() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition(
                  "node {\n"
                // Quote hell! " is Java, ''' is Groovy, ' is shell, \" is " inside XML
                + "    sh '''echo '<testsuite name=\"a\"><testcase name=\"a1\"/><testcase name=\"a2\"><error>a2 failed</error></testcase></testsuite>' > a.xml'''\n"
                + "    sh '''echo '<testsuite name=\"b\"><testcase name=\"b1\"/><testcase name=\"b2\"/></testsuite>' > b.xml'''\n"
                + "    step([$class: 'JUnitResultArchiver', testResults: '*.xml'])\n"
                + "}"));
        WorkflowRun b = r.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get());
        TestResultAction a = b.getAction(TestResultAction.class);
        assertNotNull(a);
        assertEquals(4, a.getTotalCount());
        assertEquals(1, a.getFailCount());
    }
View Full Code Here

        assertEquals(4, a.getTotalCount());
        assertEquals(1, a.getFailCount());
    }

    @Test public void javadoc() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition(
                  "node {\n"
                + "    sh 'mkdir docs && echo hello world > docs/index.html'\n"
                + "    step([$class: 'JavadocArchiver', javadocDir: 'docs'])\n"
                + "}"));
        r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        assertEquals("hello world\n", r.createWebClient().getPage(p, "javadoc/").getWebResponse().getContentAsString());
    }
View Full Code Here

TOP

Related Classes of org.jenkinsci.plugins.workflow.job.WorkflowJob$DescriptorImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.