Search in sources :

Example 81 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method getPipelineWihoutNodesAllStepsTest.

@Test
public void getPipelineWihoutNodesAllStepsTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("node {\n" + "    sh \"echo Building...\"\n" + "}\n" + "    node{\n" + "        echo \"Unit testing...\"\n" + "        sh \"echo Tests running\"\n" + "        sh \"echo Tests completed\"\n" + "    }", false));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(4, resp.size());
    String log = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + resp.get(0).get("id") + "/log/", String.class);
    assertNotNull(log);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 82 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method singleStageSequentialLastInParallel.

@Test
@Issue("JENKINS-53900")
public void singleStageSequentialLastInParallel() throws Exception {
    final String jenkinsfile = "pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage('Alpha') {\n" + "            parallel {\n" + "                stage('Blue') {\n" + "                    steps {\n" + "                        script {\n" + "                            println \"XXXX\"\n" + "                        }\n" + "                    }\n" + "                }\n" + "                stage('Red') {\n" + "                    stages {\n" + "                        stage('Green') {\n" + "                            steps {\n" + "                                script {\n" + "                                    println \"XXXX\"\n" + "                                }\n" + "                            }\n" + "                        }\n" + "                    }\n" + "                }\n" + "            }\n" + "        }\n" + "        stage('Bravo') {\n" + "            steps {\n" + "                script {\n" + "                    println \"XXXX\"\n" + "                }\n" + "            }\n" + "        }\n" + "    }\n" + "}\n";
    WorkflowJob project1 = j.createProject(WorkflowJob.class, "project1");
    project1.setDefinition(new CpsFlowDefinition(jenkinsfile, true));
    j.assertBuildStatus(Result.SUCCESS, project1.scheduleBuild2(0));
    WorkflowRun r = project1.getLastBuild();
    List<Map> resp = get("/organizations/jenkins/pipelines/project1/runs/" + r.getId() + "/nodes/", List.class);
    assertEquals("number of nodes", 5, resp.size());
    final Map<String, Object> bravoNode = resp.get(3);
    final Map<String, Object> greenNode = resp.get(4);
    assertEquals("includes Alpha node", "Alpha", resp.get(0).get("displayName"));
    assertEquals("includes Blue node", "Blue", resp.get(1).get("displayName"));
    assertEquals("includes Red node", "Red", resp.get(2).get("displayName"));
    assertEquals("includes Bravo node", "Bravo", bravoNode.get("displayName"));
    assertEquals("includes Green node", "Green", greenNode.get("displayName"));
    String bravoId = bravoNode.get("id").toString();
    List<Map<String, Object>> greenEdges = (List<Map<String, Object>>) greenNode.get("edges");
    assertEquals("green has edges", 1, greenEdges.size());
    assertEquals("green has edge pointing to bravo", bravoId, greenEdges.get(0).get("id"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) JSONObject(net.sf.json.JSONObject) RunList(hudson.util.RunList) List(java.util.List) ExtensionList(hudson.ExtensionList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 83 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method syntheticParallelFlowNodeNotSaved.

@Issue("JENKINS-47158")
@Test
public void syntheticParallelFlowNodeNotSaved() throws Exception {
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    p.setDefinition(new CpsFlowDefinition("parallel a: {\n" + "    node {\n" + "        echo 'a'\n" + "    }\n" + "}, b: {\n" + "    node {\n" + "        echo 'b'\n" + "    }\n" + "}\n", true));
    WorkflowRun b = j.buildAndAssertSuccess(p);
    get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    FlowExecution rawExec = b.getExecution();
    assert (rawExec instanceof CpsFlowExecution);
    CpsFlowExecution execution = (CpsFlowExecution) rawExec;
    File storage = execution.getStorageDir();
    // Nodes 5 and 6 are the parallel branch start nodes. Make sure no "5-parallel-synthetic.xml" and "6..." files
    // exist in the storage directory, showing we haven't saved them.
    assertFalse(new File(storage, "5-parallel-synthetic.xml").exists());
    assertFalse(new File(storage, "6-parallel-synthetic.xml").exists());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) File(java.io.File) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 84 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method downstreamBuildLinksDeclarative.

@Test
@Issue("JENKINS-38339")
public void downstreamBuildLinksDeclarative() throws Exception {
    FreeStyleProject downstream1 = j.createFreeStyleProject("downstream1");
    FreeStyleProject downstream2 = j.createFreeStyleProject("downstream2");
    WorkflowJob upstream = j.createProject(WorkflowJob.class, "upstream");
    URL resource = getClass().getResource("downstreamBuildLinksDecl.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    upstream.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    j.assertBuildStatus(Result.SUCCESS, upstream.scheduleBuild2(0));
    WorkflowRun r = upstream.getLastBuild();
    List<Map> resp = get("/organizations/jenkins/pipelines/upstream/runs/" + r.getId() + "/nodes/", List.class);
    assertEquals("number of nodes", 5, resp.size());
    Matcher actionMatcher1 = new NodeDownstreamBuildActionMatcher("downstream1");
    Matcher actionMatcher2 = new NodeDownstreamBuildActionMatcher("downstream2");
    List<Map> actions = (List<Map>) resp.get(2).get("actions");
    assertThat("node #2 contains a link to downstream1", actions, hasItem(actionMatcher1));
    actions = (List<Map>) resp.get(3).get("actions");
    assertThat("node #3 contains a link to downstream2", actions, hasItem(actionMatcher2));
    actions = (List<Map>) resp.get(4).get("actions");
    assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher1));
    assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher2));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) RunList(hudson.util.RunList) List(java.util.List) ExtensionList(hudson.ExtensionList) FreeStyleProject(hudson.model.FreeStyleProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) URL(java.net.URL) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 85 with CpsFlowDefinition

use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method submitInputPostBlock.

@Test
@Issue("JENKINS-49297")
public void submitInputPostBlock() throws Exception {
    WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    URL resource = getClass().getResource("stepsFromPost.jenkinsfile");
    String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
    job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0);
    WorkflowRun run = buildTask.getStartCondition().get();
    CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
    while (run.getAction(InputAction.class) == null) {
        e.waitForSuspension();
    }
    List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    assertEquals(1, nodes.size());
    List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(0).get("id") + "/steps/", List.class);
    assertEquals(3, steps.size());
    assertEquals("7", steps.get(0).get("id"));
    assertEquals("Hello World", steps.get(0).get("displayDescription"));
    assertEquals("12", steps.get(1).get("id"));
    assertEquals("Hello World from post", steps.get(1).get("displayDescription"));
    assertEquals("13", steps.get(2).get("id"));
    assertEquals("Wait for interactive input", steps.get(2).get("displayName"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) URL(java.net.URL) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)220 Test (org.junit.Test)210 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)182 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)124 Issue (org.jvnet.hudson.test.Issue)63 Map (java.util.Map)60 List (java.util.List)26 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RunList (hudson.util.RunList)20 ExtensionList (hudson.ExtensionList)19 Statement (org.junit.runners.model.Statement)19 Run (hudson.model.Run)17 URL (java.net.URL)16 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)12 TaskListener (hudson.model.TaskListener)11 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)10 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)6