use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineRunblockingStopTest.
//TODO: Fix test - see JENKINS-38319
//@Test
public void getPipelineRunblockingStopTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " sh('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.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineJobActivities.
@Test
public void getPipelineJobActivities() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " sleep 10000 " + " echo ('Testing'); " + "}"));
job1.setConcurrentBuild(false);
WorkflowRun r = job1.scheduleBuild2(0).waitForStart();
job1.scheduleBuild2(0);
List l = request().get("/organizations/jenkins/pipelines/pipeline1/activities").build(List.class);
Assert.assertEquals(2, l.size());
Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(1)).get("_class"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineWihoutNodesAllStepsTest.
@Test
public void getPipelineWihoutNodesAllStepsTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " sh \"echo Building...\"\n" + "}\n" + " node{\n" + " echo \"Unit testing...\"\n" + " sh \"echo Tests running\"\n" + " sh \"echo Tests completed\"\n" + " }"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(4, resp.size());
String log = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + resp.get(0).get("id") + "/log/", String.class);
assertNotNull(log);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method declarativeSyntheticSteps.
@Test
public void declarativeSyntheticSteps() throws Exception {
setupScm("pipeline {\n" + " agent any\n" + " stages {\n" + " stage(\"build\") {\n" + " steps{\n" + " sh 'echo \"Start Build\"'\n" + " echo 'End Build'\n" + " }\n" + " }\n" + " stage(\"deploy\") {\n" + " steps{\n" + " sh 'echo \"Start Deploy\"'\n" + " sh 'echo \"Deploying...\"'\n" + " sh 'echo \"End Deploy\"'\n" + " } \n" + " }\n" + " }\n" + " post {\n" + " failure {\n" + " echo \"failed\"\n" + " }\n" + " success {\n" + " echo \"success\"\n" + " }\n" + " }\n" + "}");
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
mp.scheduleBuild2(0).getFuture().get();
j.waitUntilNoActivity();
WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
j.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
Assert.assertEquals(Result.SUCCESS, b1.getResult());
List<FlowNode> stages = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
Assert.assertEquals(2, stages.size());
Assert.assertEquals("build", stages.get(0).getDisplayName());
Assert.assertEquals("deploy", stages.get(1).getDisplayName());
List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
Assert.assertEquals(2, resp.size());
Assert.assertEquals("build", resp.get(0).get("displayName"));
Assert.assertEquals("deploy", resp.get(1).get("displayName"));
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
Assert.assertEquals(7, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
Assert.assertEquals(3, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
Assert.assertEquals(4, resp.size());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun 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());
}
Aggregations