use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method parameterizedPipeline.
@Test
public void parameterizedPipeline() throws Exception {
String script = "properties([parameters([string(defaultValue: 'xyz', description: 'string param', name: 'param1'), string(description: 'string param', name: 'param2')]), pipelineTriggers([])])\n" + "\n" + "node(){\n" + " stage('build'){\n" + " echo \"building\"\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
Map resp = get("/organizations/jenkins/pipelines/pipeline1/");
List<Map<String, Object>> parameters = (List<Map<String, Object>>) resp.get("parameters");
Assert.assertEquals(2, parameters.size());
Assert.assertEquals("param1", parameters.get(0).get("name"));
Assert.assertEquals("StringParameterDefinition", parameters.get(0).get("type"));
Assert.assertEquals("string param", parameters.get(0).get("description"));
Assert.assertEquals("xyz", ((Map) parameters.get(0).get("defaultParameterValue")).get("value"));
Assert.assertEquals("param2", parameters.get(1).get("name"));
Assert.assertEquals("StringParameterDefinition", parameters.get(1).get("type"));
Assert.assertEquals("string param", parameters.get(1).get("description"));
Assert.assertNull(((Map) parameters.get(1).get("defaultParameterValue")).get("value"));
resp = post("/organizations/jenkins/pipelines/pipeline1/runs/", ImmutableMap.of("parameters", ImmutableList.of(ImmutableMap.of("name", "param1", "value", "abc"), ImmutableMap.of("name", "param2", "value", "def"))), 200);
Assert.assertEquals("pipeline1", resp.get("pipeline"));
Thread.sleep(1000);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/");
Assert.assertEquals("SUCCESS", resp.get("result"));
Assert.assertEquals("FINISHED", resp.get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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" + " }"));
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" + " }"));
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.job.WorkflowRun 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" + "}"));
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.job.WorkflowRun 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));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(6, 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"));
Assert.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(5).get("id"), edges.get(0).get("id"));
}
if (i == 3) {
assertEquals("branch2", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(5).get("id"), edges.get(0).get("id"));
}
if (i == 4) {
assertEquals("branch3", n.get("displayName"));
assertEquals(1, edges.size());
assertEquals(nodes.get(5).get("id"), edges.get(0).get("id"));
}
if (i == 5) {
assertEquals("stage2", n.get("displayName"));
assertEquals(0, edges.size());
}
}
Map synNode = nodes.get(1);
List<Map> edges = (List<Map>) synNode.get("edges");
Map n = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + synNode.get("id") + "/", Map.class);
List<Map> receivedEdges = (List<Map>) n.get("edges");
assertNotNull(n);
assertEquals(synNode.get("displayName"), n.get("displayName"));
assertEquals(synNode.get("id"), n.get("id"));
Assert.assertEquals(3, edges.size());
assertEquals(edges.get(0).get("id"), receivedEdges.get(0).get("id"));
assertEquals(edges.get(1).get("id"), receivedEdges.get(1).get("id"));
assertEquals(edges.get(2).get("id"), receivedEdges.get(2).get("id"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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());
}
Aggregations