use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method statusForTwoLevelParallelBuild.
@Test
@Issue("JENKINS-50532")
public void statusForTwoLevelParallelBuild() throws Exception {
String p = "pipeline {\n" + " agent any\n" + " stages {\n" + " stage('Nested Parallel Stage') {\n" + " parallel {\n" + " stage(\"Parallel Stage\") { \n" + " steps { \n" + " script {\n" + " def parallelTasks = [:]\n" + " \n" + " parallelTasks['Successful Task 1'] = {\n" + " echo \"Success\"\n" + " }\n" + " parallelTasks['Failing Task'] = {\n" + " sh \"exit 1\"\n" + " }\n" + " parallel parallelTasks\n" + " } \n" + " } \n" + " }\n" + " stage(\"Stage\") {\n" + " steps { \n" + " echo \"Stage\" \n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(p, false));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(resp.size(), 5);
for (Map rn : resp) {
if (rn.get("displayName").equals("Failing Task")) {
Assert.assertEquals(rn.get("state"), "FINISHED");
Assert.assertEquals(rn.get("result"), "FAILURE");
} else if (rn.get("displayName").equals("Parallel Stage")) {
Assert.assertEquals(rn.get("state"), "FINISHED");
Assert.assertEquals(rn.get("result"), "FAILURE");
} else if (rn.get("displayName").equals("Stage")) {
Assert.assertEquals(rn.get("state"), "FINISHED");
Assert.assertEquals(rn.get("result"), "SUCCESS");
} else if (rn.get("displayName").equals("Successful Task")) {
Assert.assertEquals(rn.get("state"), "FINISHED");
Assert.assertEquals(rn.get("result"), "SUCCESS");
}
}
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageNodesFailureTest2.
@Test
public void BlockStageNodesFailureTest2() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " stage ('Build') {\n" + " sh 'echo \"Building\"'\n" + " }\n" + " stage ('Test') {\n" + " sh 'echo1 testing'\n" + " }\n" + " stage ('Deploy') {\n" + " sh 'echo deploy'\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(2, nodes.size());
Assert.assertEquals("SUCCESS", nodes.get(0).get("result"));
Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
Assert.assertEquals("FAILURE", nodes.get(1).get("result"));
Assert.assertEquals("FINISHED", nodes.get(1).get("state"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodesTest.
@Test
public void nodesTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("stage (\"Build\") {\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "}\n" + "stage (\"Test\") {\n" + " parallel (\n" + " \"Firefox\" : {\n" + " node {\n" + " sh \"echo ffox\"\n" + " }\n" + " },\n" + " \"Chrome\" : {\n" + " node {\n" + " sh \"echo chrome\"\n" + " }\n" + " }\n" + " )\n" + "}\n" + "stage (\"CrashyMcgee\") {\n" + " parallel (\n" + " \"SlowButSuccess\" : {\n" + " node {\n" + " echo 'This is time well spent.'\n" + " }\n" + " },\n" + " \"DelayThenFail\" : {\n" + " node {\n" + " echo 'Not yet.'\n" + " }\n" + " }\n" + " )\n" + "\n" + "}\n" + "stage (\"Deploy\") {\n" + " node {\n" + " sh \"echo deploying\"\n" + " }\n" + "}\n", true));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
job1.setDefinition(new CpsFlowDefinition("stage (\"Build\") {\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "}\n" + "stage (\"Test\") {\n" + " parallel (\n" + " \"Firefox\" : {\n" + " node {\n" + " sh \"echo ffox\"\n" + " }\n" + " },\n" + " \"Chrome\" : {\n" + " node {\n" + " sh \"echo chrome\"\n" + " }\n" + " }\n" + " )\n" + "}\n" + "stage (\"CrashyMcgee\") {\n" + " parallel (\n" + " \"SlowButSuccess\" : {\n" + " node {\n" + " echo 'This is time well spent.'\n" + " sh 'sleep 3;'\n" + " }\n" + " },\n" + " \"DelayThenFail\" : {\n" + " node {\n" + " echo 'Fail soon.'\n" + " echo 'KABOOM!'\n" + " sh '11exit 1'\n" + " }\n" + " }\n" + " )\n" + "}\n" + "\n" + "stage (\"Deploy\") {\n" + " node {\n" + " sh \"echo deploying\"\n" + " }\n" + "}", false));
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b2);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/", List.class);
Assert.assertEquals(resp.size(), 8);
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("Test")) {
Assert.assertEquals(2, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("Firefox")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("Chrome")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("CrashyMcgee")) {
Assert.assertEquals(2, edges.size());
Assert.assertEquals(rn.get("result"), "FAILURE");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("SlowButSuccess")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("DelayThenFail")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "FAILURE");
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("Deploy")) {
Assert.assertEquals(0, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
}
}
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodeWrongFinishedStatus.
@Issue("JENKINS-53311")
@Test
public void nodeWrongFinishedStatus() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "p");
URL resource = getClass().getResource("JENKINS-53311.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
WorkflowRun build = job.scheduleBuild2(0).waitForStart();
long start = System.currentTimeMillis();
while (build.isBuilding()) {
List<Map<String, String>> nodes = get("/organizations/jenkins/pipelines/p/runs/1/nodes/", List.class);
if (nodes.size() >= 4) {
Optional<Map<String, String>> optionalMap = findNodeMap(nodes, "Nested B-1");
if (optionalMap.isPresent()) {
long now = System.currentTimeMillis();
// so if we reach 10s we exit the loop
if (TimeUnit.SECONDS.convert(now - start, TimeUnit.MILLISECONDS) >= 10) {
continue;
}
LOGGER.debug("optionalMap: {}", optionalMap);
assertEquals(build.isBuilding() ? BlueRun.BlueRunState.RUNNING.name() : BlueRun.BlueRunState.FINISHED, optionalMap.get().get("state"));
}
}
Thread.sleep(500);
}
List<Map<String, String>> nodes = get("/organizations/jenkins/pipelines/p/runs/1/nodes/", List.class);
Optional<Map<String, String>> optionalMap = findNodeMap(nodes, "Nested B-1");
if (optionalMap.isPresent()) {
assertEquals(BlueRun.BlueRunState.FINISHED.name(), optionalMap.get().get("state"));
}
j.assertBuildStatus(Result.SUCCESS, build);
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method orphanParallels2.
@Test
public void orphanParallels2() throws Exception {
String script = "stage(\"stage1\"){\n" + " echo \"stage 1...\"\n" + "}\n" + "parallel('branch1':{\n" + " node {\n" + " stage('Setup') {\n" + " sh 'echo \"Setup...\"'\n" + " }\n" + " stage('Unit and Integration Tests') {\n" + " sh 'echo \"Unit and Integration Tests...\"'\n" + " }\n" + " }\n" + "}, 'branch3': {\n" + " node {\n" + " stage('Setup') {\n" + " sh 'echo \"Branch3 setup...\"'\n" + " }\n" + " stage('Unit and Integration Tests') {\n" + " echo '\"my command to execute tests\"'\n" + " }\n" + " }\n" + "}, 'branch2': {\n" + " node {\n" + " stage('Setup') {\n" + " sh 'echo \"Branch2 setup...\"'\n" + " }\n" + " stage('Unit and Integration Tests') {\n" + " echo '\"my command to execute tests\"'\n" + " }\n" + " }\n" + "})\n" + "stage(\"stage2\"){\n" + " echo \"stage 2...\"\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script, false));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
assertEquals(12, nodes.size());
for (int i = 0; i < nodes.size(); i++) {
Map n = nodes.get(i);
List<Map> edges = (List<Map>) n.get("edges");
if (i == 0) {
assertEquals("stage1", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(i + 1).get("id"), edges.get(0).get("id"));
}
if (i == 1) {
assertEquals("Parallel", n.get("displayName"));
assertEquals(nodes.get(i + 1).get("id") + "-parallel-synthetic", n.get("id"));
assertEquals(3, edges.size());
assertEquals(nodes.get(i + 1).get("id"), edges.get(0).get("id"));
assertEquals(nodes.get(i + 2).get("id"), edges.get(1).get("id"));
assertEquals(nodes.get(i + 3).get("id"), edges.get(2).get("id"));
}
if (i == 2) {
assertEquals("branch1", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(6).get("id"), edges.get(0).get("id"));
}
if (i == 3) {
assertEquals("branch2", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(10).get("id"), edges.get(0).get("id"));
}
if (i == 4) {
assertEquals("branch3", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(8).get("id"), edges.get(0).get("id"));
}
if (i == 5) {
assertEquals("stage2", n.get("displayName"));
assertEquals(0, edges.size());
}
if (i == 6) {
assertEquals("Setup", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(7).get("id"), edges.get(0).get("id"));
}
if (i == 7) {
assertEquals("Unit and Integration Tests", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(5).get("id"), edges.get(0).get("id"));
}
if (i == 8) {
assertEquals("Setup", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(9).get("id"), edges.get(0).get("id"));
}
if (i == 9) {
assertEquals("Unit and Integration Tests", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(5).get("id"), edges.get(0).get("id"));
}
if (i == 10) {
assertEquals("Setup", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(11).get("id"), edges.get(0).get("id"));
}
if (i == 11) {
assertEquals("Unit and Integration Tests", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(5).get("id"), edges.get(0).get("id"));
}
}
}
Aggregations