use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodesWithFutureTest.
@Test
public void nodesWithFutureTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node {\n" + " stage 'build'\n" + " sh 'echo s1'\n" + " stage 'test'\n" + " echo 'Hello World 2'\n" + "}", false));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
job1.setDefinition(new CpsFlowDefinition("node {\n" + " stage 'build'\n" + " sh 'echo s1'\n" + " stage 'test'\n" + " echo 'Hello World 2'\n" + "}\n" + "parallel firstBranch: {\n" + " echo 'Hello first'\n" + "}, secondBranch: {\n" + " echo 'Hello second'\n" + "}", false));
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b2);
job1.setDefinition(new CpsFlowDefinition("node {\n" + " stage 'build'\n" + " sh 'echo s1'\n" + " stage 'test'\n" + " echo 'Hello World 2'\n" + "}\n" + "parallel firstBranch: {\n" + " echo 'Hello first'\n" + "}, secondBranch: {\n" + " sh 'Hello second'\n" + "}", false));
WorkflowRun b3 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b3);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(2, resp.size());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageStepsWithDesc.
@Test
public void BlockStageStepsWithDesc() 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 'echo testing'\n" + " }\n" + " stage ('Deploy') {\n" + " sh 'echo deploy'\n" + " }\n" + "}", false));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(3, steps.size());
Assert.assertEquals("Shell Script", steps.get(0).get("displayName"));
Assert.assertEquals("Shell Script", steps.get(1).get("displayName"));
Assert.assertEquals("Shell Script", steps.get(2).get("displayName"));
Assert.assertEquals("echo \"Building\"", steps.get(0).get("displayDescription"));
Assert.assertEquals("echo testing", steps.get(1).get("displayDescription"));
Assert.assertEquals("echo deploy", steps.get(2).get("displayDescription"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method successfulStepWithBlockFailureAfterward.
@Test
@Issue("JENKINS-44742")
public void successfulStepWithBlockFailureAfterward() throws Exception {
WorkflowJob p = j.createProject(WorkflowJob.class, "project");
URL resource = getClass().getResource("successfulStepWithBlockFailureAfterward.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
p.save();
Run r = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(r);
List<Map> resp = get("/organizations/jenkins/pipelines/project/runs/" + r.getId() + "/steps/", List.class);
Map firstStep = resp.get(0);
Assert.assertEquals("SUCCESS", firstStep.get("result"));
Assert.assertEquals("FINISHED", firstStep.get("state"));
Map secondStep = resp.get(1);
Assert.assertEquals("FAILURE", secondStep.get("result"));
Assert.assertEquals("FINISHED", secondStep.get("state"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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, false));
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(Util.fixEmpty((String) ((Map) parameters.get(1).get("defaultParameterValue")).get("value")));
resp = post("/organizations/jenkins/pipelines/pipeline1/runs/", MapsHelper.of("parameters", Arrays.asList(MapsHelper.of("name", "param1", "value", "abc"), MapsHelper.of("name", "param2", "value", "def"))), 200);
Assert.assertEquals("pipeline1", resp.get("pipeline"));
Thread.sleep(5000);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/");
Assert.assertEquals("Response should be SUCCESS: " + resp.toString(), "SUCCESS", resp.get("result"));
Assert.assertEquals("Response should be FINISHED: " + resp.toString(), "FINISHED", resp.get("state"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testBlockStage.
@Test
public void testBlockStage() throws Exception {
String pipeline = "" + "node {\n" + // 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, false));
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());
}
Aggregations