Package org.jenkinsci.plugins.workflow.job

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


    @Rule public JenkinsRule r = new JenkinsRule();

    @Test public void build() throws Exception {
        Maven.MavenInstallation tool = r.configureMaven3();
        String name = tool.getName();
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition("node {def home = tool '" + name + "'; sh \"${home}/bin/mvn -version\"}"));
        r.assertLogContains("Apache Maven 3", r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    }
View Full Code Here


        r.assertLogContains("Fetching changes from the remote Git repository", b); // GitSCM.retrieveChanges
        r.assertLogContains("PRESENT: nextfile", b);
    }

    @Test public void changelogAndPolling() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo");
        p.addTrigger(new SCMTrigger("")); // no schedule, use notifyCommit only
        r.createOnlineSlave(Label.get("remote"));
        p.setDefinition(new CpsFlowDefinition(
            "node('remote') {\n" +
            "    ws {\n" +
            "        git(url: '" + sampleRepo + "')\n" +
            "    }\n" +
            "}"));
        WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        r.assertLogContains("Cloning the remote Git repository", b);
        FileUtils.touch(new File(sampleRepo, "nextfile"));
        git(sampleRepo, "add", "nextfile");
        git(sampleRepo, "commit", "--message=next");
        System.out.println(r.createWebClient().goTo("git/notifyCommit?url=" + URLEncoder.encode(sampleRepo.getAbsolutePath(), "UTF-8"), "text/plain").getWebResponse().getContentAsString());
        r.waitUntilNoActivity();
        b = p.getLastBuild();
        assertEquals(2, b.number);
        r.assertLogContains("Fetching changes from the remote Git repository", b);
        List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
        assertEquals(1, changeSets.size());
        ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0);
View Full Code Here

        File otherRepo = tmp.newFolder();
        git(otherRepo, "init");
        FileUtils.touch(new File(otherRepo, "otherfile"));
        git(otherRepo, "add", "otherfile");
        git(otherRepo, "commit", "--message=init");
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo");
        p.addTrigger(new SCMTrigger(""));
        p.setQuietPeriod(3); // so it only does one build
        p.setDefinition(new CpsFlowDefinition(
            "node {\n" +
            "    ws {\n" +
            "        dir('main') {\n" +
            "            git(url: '" + sampleRepo + "')\n" +
            "        }\n" +
            "        dir('other') {\n" +
            "            git(url: '" + otherRepo + "')\n" +
            "        }\n" +
            "        sh 'for f in */*; do echo PRESENT: $f; done'\n" +
            "    }\n" +
            "}"));
        WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        r.assertLogContains("PRESENT: main/file", b);
        r.assertLogContains("PRESENT: other/otherfile", b);
        FileUtils.touch(new File(sampleRepo, "file2"));
        git(sampleRepo, "add", "file2");
        git(sampleRepo, "commit", "--message=file2");
        FileUtils.touch(new File(otherRepo, "otherfile2"));
        git(otherRepo, "add", "otherfile2");
        git(otherRepo, "commit", "--message=otherfile2");
        System.out.println(r.createWebClient().goTo("git/notifyCommit?url=" + URLEncoder.encode(sampleRepo.getAbsolutePath(), "UTF-8"), "text/plain").getWebResponse().getContentAsString());
        System.out.println(r.createWebClient().goTo("git/notifyCommit?url=" + URLEncoder.encode(otherRepo.getAbsolutePath(), "UTF-8"), "text/plain").getWebResponse().getContentAsString());
        r.waitUntilNoActivity();
        b = p.getLastBuild();
        assertEquals(2, b.number);
        r.assertLogContains("PRESENT: main/file2", b);
        r.assertLogContains("PRESENT: other/otherfile2", b);
        Iterator<? extends SCM> scms = p.getSCMs().iterator();
        assertTrue(scms.hasNext());
        assertEquals(sampleRepo.getAbsolutePath(), ((GitSCM) scms.next()).getRepositories().get(0).getURIs().get(0).toString());
        assertTrue(scms.hasNext());
        assertEquals(otherRepo.getAbsolutePath(), ((GitSCM) scms.next()).getRepositories().get(0).getURIs().get(0).toString());
        assertFalse(scms.hasNext());
View Full Code Here

        File otherWc = tmp.newFolder();
        run(otherWc, "svn", "co", otherRepoU, ".");
        FileUtils.touch(new File(otherWc, "otherfile"));
        run(otherWc, "svn", "add", "otherfile");
        run(otherWc, "svn", "commit", "--message=init");
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo");
        p.addTrigger(new SCMTrigger(""));
        p.setQuietPeriod(3); // so it only does one build
        p.setDefinition(new CpsFlowDefinition(
            "node {\n" +
            "    ws {\n" +
            "        dir('main') {\n" +
            "            svn(url: '" + sampleRepoU + "')\n" +
            "        }\n" +
            "        dir('other') {\n" +
            "            svn(url: '" + otherRepoU + "')\n" +
            "        }\n" +
            "        sh 'for f in */*; do echo PRESENT: $f; done'\n" +
            "    }\n" +
            "}"));
        WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
        r.assertLogContains("PRESENT: main/file", b);
        r.assertLogContains("PRESENT: other/otherfile", b);
        FileUtils.touch(new File(sampleWc, "file2"));
        run(sampleWc, "svn", "add", "file2");
        run(sampleWc, "svn", "commit", "--message=+file2");
        FileUtils.touch(new File(otherWc, "otherfile2"));
        run(otherWc, "svn", "add", "otherfile2");
        run(otherWc, "svn", "commit", "--message=+otherfile2");
        notifyCommit(uuid(sampleRepoU), "file2");
        notifyCommit(uuid(otherRepoU), "otherfile2");
        r.waitUntilNoActivity();
        b = p.getLastBuild();
        assertEquals(2, b.number);
        r.assertLogContains("PRESENT: main/file2", b);
        r.assertLogContains("PRESENT: other/otherfile2", b);
        Iterator<? extends SCM> scms = p.getSCMs().iterator();
        assertTrue(scms.hasNext());
        assertEquals(sampleRepoU, ((SubversionSCM) scms.next()).getLocations()[0].getURL());
        assertTrue(scms.hasNext());
        assertEquals(otherRepoU, ((SubversionSCM) scms.next()).getLocations()[0].getURL());
        assertFalse(scms.hasNext());
View Full Code Here

     * Failure in the shell script should mark the step as red
     */
    @Test
    public void failureShouldMarkNodeRed() throws Exception {
        // job setup
        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
                "node {",
                "  sh 'false'",
                "}"
        ), "\n")));


        // get the build going, and wait until workflow pauses
        WorkflowRun b = j.assertBuildStatus(Result.FAILURE, foo.scheduleBuild2(0).get());

        boolean found = false;
        FlowGraphTable t = new FlowGraphTable(b.getExecution());
        t.build();
        for (Row r : t.getRows()) {
View Full Code Here

    public void abort() throws Exception {
        File tmp = File.createTempFile("jenkins","test");
        tmp.delete();

        // job setup
        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
                "node {",
                "  sh 'while true; do touch "+tmp+"; sleep 1; done'",
                "}"
        ), "\n")));

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

        // at this point the file should be being touched
        waitForCond(5000, tmp, new Predicate<File>() {
View Full Code Here

    public void buildTopLevelProject() throws Exception {
        FreeStyleProject p = j.createFreeStyleProject("test1");
        p.getBuildersList().add(new Shell("echo 'Hello World'"));


        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList("build('test1');"), "\n")));

        QueueTaskFuture<WorkflowRun> q = foo.scheduleBuild2(0);
        j.assertBuildStatusSuccess(q);
    }
View Full Code Here

        MockFolder dir1 = j.createFolder("dir1");
        FreeStyleProject downstream = dir1.createProject(FreeStyleProject.class, "downstream");
        downstream.getBuildersList().add(new Shell("echo 'Hello World'"));

        MockFolder dir2 = j.createFolder("dir2");
        WorkflowJob upstream = dir2.createProject(WorkflowJob.class, "upstream");
        upstream.setDefinition(new CpsFlowDefinition("build '../dir1/downstream'"));

        QueueTaskFuture<WorkflowRun> q = upstream.scheduleBuild2(0);
        j.assertBuildStatusSuccess(q);
        assertEquals(1, downstream.getBuilds().size());
    }
View Full Code Here

        p2.getBuildersList().add(new Shell("echo 'Hello World'"));




        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList("parallel(test1: {\n" +
                "          build('test1');\n" +
                "        }, test2: {\n" +
                "          build('test2');\n" +
                "        })"), "\n")));

        QueueTaskFuture<WorkflowRun> q = foo.scheduleBuild2(0);
        j.assertBuildStatusSuccess(q);
    }
View Full Code Here

    @Test
    public void abortBuild() throws Exception {
        FreeStyleProject p = j.createFreeStyleProject("test1");
        p.getBuildersList().add(new Shell("sleep 6000"));

        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList("build('test1');"), "\n")));

        QueueTaskFuture<WorkflowRun> q = foo.scheduleBuild2(0);
        WorkflowRun b = q.getStartCondition().get();

        CpsFlowExecution e = (CpsFlowExecution) b.getExecutionPromise().get();
        e.waitForSuspension();
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.