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"));
}
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());
}
}
}
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"));
}
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);
}
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);
}
Aggregations