Search in sources :

Example 76 with CpsFlowDefinition

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

the class PipelineNodeTest method KyotoNodesFailureTest1.

@Test
public void KyotoNodesFailureTest1() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage ('Build') {\n" + "steps{\n" + "            sh 'echo1 \"Building\"'\n" + "        }\n" + "}\n" + "        stage ('Test') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\n" + "        }\n" + "}\n" + "        stage ('Deploy') {\n" + "steps{\n" + "            sh 'echo \"Building\"'\n" + "        }\n" + "}\n" + "    }\n" + "}\n", false));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.FAILURE, b1);
    List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(3, nodes.size());
    Assert.assertEquals("FAILURE", nodes.get(0).get("result"));
    Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
    Assert.assertEquals("NOT_BUILT", nodes.get(1).get("result"));
    Assert.assertEquals("SKIPPED", nodes.get(1).get("state"));
    Assert.assertEquals("NOT_BUILT", nodes.get(2).get("result"));
    Assert.assertEquals("SKIPPED", nodes.get(2).get("state"));
}
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 77 with CpsFlowDefinition

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

the class PipelineNodeTest method getPipelineJobRunNodesTest.

@Test
public void getPipelineJobRunNodesTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("stage ('build') {\n" + "    node {\n" + "        echo \"Building...\"\n" + "    }\n" + "}\n" + "stage ('test') {\n" + "    parallel 'unit':{\n" + "        node{\n" + "            echo \"Unit testing...\"\n" + "        }\n" + "    },\n" + "    'integration':{\n" + "        node{\n" + "            echo \"Integration testing...\"\n" + "        }\n" + "    },\n" + "    'ui':{\n" + "        node{\n" + "            echo \"UI testing...\"\n" + "        }\n" + "    }\n" + "}\n" + "stage ('deploy') {\n" + "    node{\n" + "        echo \"Deploying\"\n" + "    }\n" + "}\n" + "stage ('deployToProd') {\n" + "    node{\n" + "        echo \"Deploying to production\"\n" + "    }\n" + "}", false));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
    List<FlowNode> nodes = getStagesAndParallels(builder);
    List<FlowNode> parallelNodes = getParallelNodes(builder);
    Assert.assertEquals(7, nodes.size());
    Assert.assertEquals(3, parallelNodes.size());
    List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
    Assert.assertEquals(nodes.size(), resp.size());
    for (int i = 0; i < nodes.size(); i++) {
        FlowNode n = nodes.get(i);
        Map rn = resp.get(i);
        Assert.assertEquals(n.getId(), rn.get("id"));
        Assert.assertEquals(getNodeName(n), rn.get("displayName"));
        Assert.assertEquals("SUCCESS", rn.get("result"));
        List<Map> edges = (List<Map>) rn.get("edges");
        Assert.assertTrue((int) rn.get("durationInMillis") > 0);
        if (n.getDisplayName().equals("test")) {
            Assert.assertEquals(parallelNodes.size(), edges.size());
            Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
        } else if (n.getDisplayName().equals("build")) {
            Assert.assertEquals(1, edges.size());
            Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
        } else if (n.getDisplayName().equals("deploy")) {
            Assert.assertEquals(1, edges.size());
        } else if (n.getDisplayName().equals("deployToProd")) {
            Assert.assertEquals(0, edges.size());
        } else {
            Assert.assertEquals(1, edges.size());
            Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
        }
    }
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) 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) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 78 with CpsFlowDefinition

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

the class PipelineApiTest method pipelineJobCapabilityTest.

@Test
public void pipelineJobCapabilityTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sleep(60); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    Map response = get("/organizations/jenkins/pipelines/pipeline1/");
    String clazz = (String) response.get("_class");
    response = get("/classes/" + clazz + "/");
    Assert.assertNotNull(response);
    List<String> classes = (List<String>) response.get("classes");
    Assert.assertTrue(classes.contains("hudson.model.Job") && classes.contains("org.jenkinsci.plugins.workflow.job.WorkflowJob") && classes.contains("io.jenkins.blueocean.rest.model.BluePipeline") && !classes.contains("io.jenkins.blueocean.rest.model.BlueBranch"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) List(java.util.List) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) Test(org.junit.Test)

Example 79 with CpsFlowDefinition

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

the class PipelineApiTest method getPipelineRunblockingStopTest.

// TODO: Fix test - see JENKINS-38319
@Test
@Ignore
public void getPipelineRunblockingStopTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   sleep(60);" + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
    Map r = // default timeOutInSecs=10 sec
    request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop/?blocking=true").build(Map.class);
    Assert.assertEquals(r.get("state"), "FINISHED");
    Assert.assertEquals(r.get("result"), "ABORTED");
    j.assertBuildStatus(Result.ABORTED, b1);
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 80 with CpsFlowDefinition

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

the class PipelineApiTest method getPipelineJobRunTest.

@Test
public void getPipelineJobRunTest() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("" + "node {" + "   stage ('Build1'); " + "   echo ('Building'); " + "   stage ('Test1'); " + "   echo ('Testing'); " + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatusSuccess(b1);
    Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1");
    validateRun(b1, resp);
}
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)

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