Package org.jenkinsci.plugins.workflow.cps

Examples of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition


                DumbSlave s = createSlave(story.j);
                s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONSLAVE", "true")));

                p = jenkins().createProject(WorkflowJob.class, "demo");
                dir.set(s.getRemoteFS() + "/workspace/" + p.getFullName());
                p.setDefinition(new CpsFlowDefinition(
                    "node('" + s.getNodeName() + "') {\n" +
                    "    sh('pwd; echo ONSLAVE=$ONSLAVE')\n" +
                    "}"));

                startBuilding();
View Full Code Here


                @SuppressWarnings("deprecation")
                String slaveRoot = story.j.createTmpDir().getPath();
                jenkins().addNode(new DumbSlave("slave", "dummy", slaveRoot, "2", Node.Mode.NORMAL, "", story.j.createComputerLauncher(null), RetentionStrategy.NOOP, Collections.<NodeProperty<?>>emptyList()));
                p = jenkins().createProject(WorkflowJob.class, "demo");
                p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("FLAG", null)));
                p.setDefinition(new CpsFlowDefinition(
                        "node('slave') {\n" + // this locks the WS
                                "    sh('echo default=`basename $PWD`')\n" +
                                "    ws {\n" + // and this locks a second one
                                "        sh('echo before=`basename $PWD`')\n" +
                                "        watch(new File('" + jenkins().getRootDir() + "', FLAG))\n" +
View Full Code Here

     */
    @Test public void invokeBodyLaterAfterRestart() throws Exception {
        story.addStep(new Statement() {
            @Override public void evaluate() throws Throwable {
                p = jenkins().createProject(WorkflowJob.class, "demo");
                p.setDefinition(new CpsFlowDefinition(
                    "import " + SimulatedFailureForRetry.class.getName() + ";\n"+
                    "int count=0;\n" +
                    "retry(3) {\n" +
                        // we'll suspend the execution here
                    "    watch(new File('" + jenkins().getRootDir() + "/touch'))\n" +
View Full Code Here

            @Override public void evaluate() throws Throwable {
                jenkins().setSecurityRealm(story.j.createDummySecurityRealm());
                jenkins().save();
                QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(new MockQueueItemAuthenticator(Collections.singletonMap("demo", User.get("someone").impersonate())));
                p = jenkins().createProject(WorkflowJob.class, "demo");
                p.setDefinition(new CpsFlowDefinition("checkAuth()"));
                ScriptApproval.get().preapproveAll();
                startBuilding();
                waitForWorkflowToSuspend();
                assertTrue(JenkinsRule.getLog(b), b.isBuilding());
                Thread.sleep(1500); // TODO how else to ensure that WorkflowRun.waitForCompletion has called copyLogs? (it flushes logs when a step finishes but cannot tell when start() returns, and it cannot listen for LogAction being added or written)
View Full Code Here

    @Test public void env() {
        story.addStep(new Statement() {
            @Override public void evaluate() throws Throwable {
                p = jenkins().createProject(WorkflowJob.class, "demo");
                p.setDefinition(new CpsFlowDefinition("node {sh 'echo tag=$BUILD_TAG'; env.BUILD_TAG='custom'; sh 'echo tag2=$BUILD_TAG'; env.STUFF='more'; watch new File('" + jenkins().getRootDir() + "/touch'); env.BUILD_TAG=\"${env.BUILD_TAG}2\"; sh 'echo tag3=$BUILD_TAG stuff=$STUFF'}"));
                startBuilding();
                while (watchDescriptor.getActiveWatches().isEmpty()) {
                    assertTrue(JenkinsRule.getLog(b), b.isBuilding());
                    waitForWorkflowToSuspend();
                }
View Full Code Here

    @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 {def cwd = pwd(); sh \"echo cwd='$cwd'\"}"));
        r.assertLogContains("cwd=" + r.jenkins.getWorkspaceFor(p), r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
    }
View Full Code Here

        hg(otherRepo, "add", "otherfile");
        hg(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" +
            "            checkout([$class: 'MercurialSCM', source: '" + sampleRepo + "'])\n" +
            "        }\n" +
View Full Code Here

     */
    @Test
    public void archive() throws Exception {
        // job setup
        WorkflowJob foo = j.jenkins.createProject(WorkflowJob.class, "foo");
        foo.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
                "node {",
                "  sh 'echo hello world > msg'",
                "  archive 'm*'",
                "  unarchive(mapping:['msg':'msg.out'])",
                "  archive 'msg.out'",
View Full Code Here

        assertEquals("hello world\n",IOUtils.toString(archivedFile.open()));
    }

    @Test public void unarchiveDir() throws Exception {
        WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition(StringUtils.join(Arrays.asList(
                "node {",
                "  sh 'mkdir -p a/b && echo one > a/1 && echo two > a/b/2'",
                "  archive 'a/'",
                "  sh 'rm -r a'",
                "  unarchive mapping: ['a/' : '.']",
View Full Code Here

     * The simplest possible timeout step ever.
     */
    @Test
    public void basic() throws Exception {
        WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
        p.setDefinition(new CpsFlowDefinition(
                "import java.util.concurrent.*; node { timeout(time:5, unit:TimeUnit.SECONDS) { sh 'sleep 10'; echo 'NotHere' } }"));
        WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
        r.assertLogNotContains("NotHere", b);
    }
View Full Code Here

TOP

Related Classes of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition

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.