use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testBlockStage.
@Test
public void testBlockStage() throws Exception {
String pipeline = "" + "node {" + //start
" stage ('dev');" + " echo ('development'); " + " stage ('Build') { " + " echo ('Building'); " + " } \n" + " stage ('test') { " + " echo ('Testing'); " + //1
" parallel firstBranch: {\n" + " echo 'first Branch'\n" + " sh 'sleep 1'\n" + " echo 'first Branch end'\n" + " }, secondBranch: {\n" + " echo 'Hello second Branch'\n" + " sh 'sleep 1' \n" + " echo 'second Branch end'\n" + " \n" + " },\n" + " failFast: false\n" + " } \n" + " stage ('deploy') { " + " writeFile file: 'file.txt', text:'content'; " + " archive(includes: 'file.txt'); " + " echo ('Deploying'); " + " } \n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(pipeline));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> stages = getStages(builder);
List<FlowNode> parallels = getParallelNodes(builder);
;
Assert.assertEquals(4, stages.size());
Assert.assertEquals(2, parallels.size());
//TODO: complete test
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(6, resp.size());
String testStageId = null;
for (int i = 0; i < resp.size(); i++) {
Map rn = resp.get(i);
List<Map> edges = (List<Map>) rn.get("edges");
if (rn.get("displayName").equals("dev")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("test")) {
testStageId = (String) rn.get("id");
Assert.assertEquals(2, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("firstBranch")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("secondBranch")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("deploy")) {
Assert.assertEquals(0, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
}
}
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(12, resp.size());
Assert.assertNotNull(testStageId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + testStageId + "/steps/", List.class);
Assert.assertEquals(7, resp.size());
}
use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testNonblockStageSteps.
@Test
public void testNonblockStageSteps() throws Exception {
String pipeline = "node {\n" + " stage 'Checkout'\n" + " echo 'checkingout'\n" + " stage 'Build'\n" + " echo 'building'\n" + " stage 'Archive'\n" + " echo 'archiving...'\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(pipeline));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> stages = getStages(builder);
List<FlowNode> parallels = getParallelNodes(builder);
Assert.assertEquals(3, stages.size());
Assert.assertEquals(0, parallels.size());
//TODO: complete test
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(3, resp.size());
String checkoutId = (String) resp.get(0).get("id");
String buildId = (String) resp.get(0).get("id");
String archiveId = (String) resp.get(0).get("id");
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(3, resp.size());
Assert.assertNotNull(checkoutId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + checkoutId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertNotNull(buildId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + buildId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertNotNull(archiveId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + archiveId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
}
use of org.jenkinsci.plugins.workflow.graph.FlowNode 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" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + " echo \"Deploying to production\"\n" + "}"));
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.graph.FlowNode in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineJobRunNodesTestWithFuture.
@Test
public void getPipelineJobRunNodesTestWithFuture() 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" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + " echo \"Deploying to production\"\n" + "}"));
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");
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());
}
}
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" + //fail the build intentionally
" sh \"`fail-the-build`\"\n" + " }\n" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + " echo \"Deploying to production\"\n" + "}"));
b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
resp = get(String.format("/organizations/jenkins/pipelines/pipeline1/runs/%s/nodes/", b1.getId()), 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"));
List<Map> edges = (List<Map>) rn.get("edges");
if (n.getDisplayName().equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (n.getDisplayName().equals("test")) {
Assert.assertEquals(parallelNodes.size(), edges.size());
Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (PipelineNodeUtil.getDisplayName(n).equals("unit")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (n.getDisplayName().equals("deploy")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
Assert.assertNull(rn.get("startTime"));
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 1).getId());
} else if (n.getDisplayName().equals("deployToProd")) {
Assert.assertEquals(0, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
Assert.assertNull(rn.get("startTime"));
Assert.assertEquals(0, edges.size());
} else {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
}
}
}
use of org.jenkinsci.plugins.workflow.graph.FlowNode in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineJobRunNodesWithFailureTest.
@Test
public void getPipelineJobRunNodesWithFailureTest() 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" + //fail the build intentionally
" sh \"`fail-the-build`\"\n" + " }\n" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> nodes = getStagesAndParallels(builder);
List<FlowNode> parallelNodes = getParallelNodes(builder);
Assert.assertEquals(5, 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());
String unitNodeId = null;
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"));
List<Map> edges = (List<Map>) rn.get("edges");
if (n.getDisplayName().equals("test")) {
Assert.assertEquals(parallelNodes.size(), edges.size());
Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
} else if (n.getDisplayName().equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
} else if (n.getDisplayName().equals("Branch: unit")) {
unitNodeId = n.getId();
Assert.assertEquals(0, edges.size());
Assert.assertEquals("FAILURE", rn.get("result"));
} else {
Assert.assertEquals(0, edges.size());
Assert.assertEquals("SUCCESS", rn.get("result"));
}
}
assertNotNull(unitNodeId);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + unitNodeId + "/steps/", List.class);
String log = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + unitNodeId + "/log/", String.class);
assertNotNull(log);
}
Aggregations