use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeUtil method getCauseOfBlockage.
/**
* Gives cause of block for declarative style plugin where agent (node block) is declared inside a stage.
* <pre>
* pipeline {
* agent none
* stages {
* stage ('first') {
* agent {
* label 'first'
* }
* steps{
* sh 'echo "from first"'
* }
* }
* }
* }
* </pre>
*
* @param stage stage's {@link FlowNode}
* @param nodeBlock agent or node block's {@link FlowNode}
* @param run {@link WorkflowRun} instance
* @return cause of block if present, nul otherwise
* @throws IOException in case of IOException
* @throws InterruptedException in case of Interrupted exception
*/
@CheckForNull
public static String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock, @Nonnull WorkflowRun run) throws IOException, InterruptedException {
if (nodeBlock != null) {
//Check and see if this node block is inside this stage
for (FlowNode p : nodeBlock.getParents()) {
if (p.equals(stage)) {
//see if there is blocked item in queue
for (Queue.Item i : Jenkins.getInstance().getQueue().getItems()) {
if (i.task instanceof ExecutorStepExecution.PlaceholderTask) {
ExecutorStepExecution.PlaceholderTask task = (ExecutorStepExecution.PlaceholderTask) i.task;
String cause = i.getCauseOfBlockage().getShortDescription();
if (task.getCauseOfBlockage() != null) {
cause = task.getCauseOfBlockage().getShortDescription();
}
Run r = task.runForDisplay();
//Set cause if its there and run and node block in the queue is same as the one we
if (cause != null && r != null && r.equals(run) && task.getNode() != null && task.getNode().equals(nodeBlock)) {
return cause;
}
}
}
}
}
}
return null;
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getMultiBranchPipelineRunStages.
@Test
public void getMultiBranchPipelineRunStages() throws Exception {
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
j.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(3, mp.getItems().size());
j.waitForCompletion(b1);
List<Map> nodes = get("/organizations/jenkins/pipelines/p/branches/master/runs/1/nodes", List.class);
Assert.assertEquals(3, nodes.size());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageNodesFailureTest1.
@Test
public void BlockStageNodesFailureTest1() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " stage ('Build') {\n" + " sh 'echo1 \"Building\"'\n" + " }\n" + " stage ('Test') {\n" + " sh 'echo 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(1, nodes.size());
Assert.assertEquals("FAILURE", nodes.get(0).get("result"));
Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageNodesFailureTest3.
@Test
public void BlockStageNodesFailureTest3() 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 'echo1 deploy'\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(3, nodes.size());
Assert.assertEquals("SUCCESS", nodes.get(0).get("result"));
Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
Assert.assertEquals("SUCCESS", nodes.get(1).get("result"));
Assert.assertEquals("FINISHED", nodes.get(1).get("state"));
Assert.assertEquals("FAILURE", nodes.get(2).get("result"));
Assert.assertEquals("FINISHED", nodes.get(2).get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodesFailureTest.
@Test
public void nodesFailureTest() 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);
job1.setDefinition(new CpsFlowDefinition("throw 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" + " }"));
job1.scheduleBuild2(0);
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(8, resp.size());
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.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Firefox")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Chrome")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("CrashyMcgee")) {
Assert.assertEquals(2, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("SlowButSuccess")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("DelayThenFail")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Deploy")) {
Assert.assertEquals(0, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
}
}
}
Aggregations