use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method downstreamBuildLinks.
@Test
@Issue("JENKINS-38339")
public void downstreamBuildLinks() throws Exception {
FreeStyleProject downstream1 = j.createFreeStyleProject("downstream1");
FreeStyleProject downstream2 = j.createFreeStyleProject("downstream2");
WorkflowJob upstream = j.createProject(WorkflowJob.class, "upstream");
URL resource = Resources.getResource(getClass(), "downstreamBuildLinks.jenkinsfile");
String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
upstream.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
j.assertBuildStatus(Result.SUCCESS, upstream.scheduleBuild2(0));
WorkflowRun r = upstream.getLastBuild();
List<Map> resp = get("/organizations/jenkins/pipelines/upstream/runs/" + r.getId() + "/nodes/", List.class);
assertEquals("number of nodes", 5, resp.size());
Matcher actionMatcher1 = new NodeDownstreamBuildActionMatcher("downstream1");
Matcher actionMatcher2 = new NodeDownstreamBuildActionMatcher("downstream2");
List<Map> actions = (List<Map>) resp.get(2).get("actions");
assertThat("node #2 contains a link to downstream1", actions, hasItem(actionMatcher1));
actions = (List<Map>) resp.get(3).get("actions");
assertThat("node #3 contains a link to downstream2", actions, hasItem(actionMatcher2));
actions = (List<Map>) resp.get(4).get("actions");
assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher1));
assertThat("node #4 contains a link to downstream1", actions, hasItem(actionMatcher2));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineJobRunNodesTestWithFuture.
@Test
public void getPipelineJobRunNodesTestWithFuture() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + " echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + " node{\n" + " echo \"Unit testing...\"\n" + " }\n" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + " echo \"Deploying to production\"\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> nodes = getStagesAndParallels(builder);
List<FlowNode> parallelNodes = getParallelNodes(builder);
Assert.assertEquals(7, nodes.size());
Assert.assertEquals(3, parallelNodes.size());
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(nodes.size(), resp.size());
for (int i = 0; i < nodes.size(); i++) {
FlowNode n = nodes.get(i);
Map rn = resp.get(i);
Assert.assertEquals(n.getId(), rn.get("id"));
Assert.assertEquals(getNodeName(n), rn.get("displayName"));
Assert.assertEquals("SUCCESS", rn.get("result"));
List<Map> edges = (List<Map>) rn.get("edges");
if (n.getDisplayName().equals("test")) {
Assert.assertEquals(parallelNodes.size(), edges.size());
Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
} else if (n.getDisplayName().equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
} else if (n.getDisplayName().equals("deploy")) {
Assert.assertEquals(1, edges.size());
} else if (n.getDisplayName().equals("deployToProd")) {
Assert.assertEquals(0, edges.size());
} else {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
}
}
job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + " echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + " node{\n" + " echo \"Unit testing...\"\n" + // fail the build intentionally
" sh \"`fail-the-build`\"\n" + " }\n" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}" + "\n" + "stage 'deployToProd'\n" + "node{\n" + " echo \"Deploying to production\"\n" + "}"));
b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
resp = get(String.format("/organizations/jenkins/pipelines/pipeline1/runs/%s/nodes/", b1.getId()), List.class);
Assert.assertEquals(nodes.size(), resp.size());
for (int i = 0; i < nodes.size(); i++) {
FlowNode n = nodes.get(i);
Map rn = resp.get(i);
Assert.assertEquals(n.getId(), rn.get("id"));
Assert.assertEquals(getNodeName(n), rn.get("displayName"));
List<Map> edges = (List<Map>) rn.get("edges");
if (n.getDisplayName().equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (n.getDisplayName().equals("test")) {
Assert.assertEquals(parallelNodes.size(), edges.size());
Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (PipelineNodeUtil.getDisplayName(n).equals("unit")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
} else if (n.getDisplayName().equals("deploy")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
Assert.assertNull(rn.get("startTime"));
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 1).getId());
} else if (n.getDisplayName().equals("deployToProd")) {
Assert.assertEquals(0, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
Assert.assertNull(rn.get("startTime"));
Assert.assertEquals(0, edges.size());
} else {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(0).get("id"), nodes.get(nodes.size() - 2).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
Assert.assertEquals("FINISHED", rn.get("state"));
}
}
}
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());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method syntheticParallelFlowNodeNotSaved.
@Issue("JENKINS-47158")
@Test
public void syntheticParallelFlowNodeNotSaved() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
p.setDefinition(new CpsFlowDefinition("parallel a: {\n" + " node {\n" + " echo 'a'\n" + " }\n" + "}, b: {\n" + " node {\n" + " echo 'b'\n" + " }\n" + "}\n", true));
WorkflowRun b = j.buildAndAssertSuccess(p);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
FlowExecution rawExec = b.getExecution();
assert (rawExec instanceof CpsFlowExecution);
CpsFlowExecution execution = (CpsFlowExecution) rawExec;
File storage = execution.getStorageDir();
// Nodes 5 and 6 are the parallel branch start nodes. Make sure no "5-parallel-synthetic.xml" and "6..." files
// exist in the storage directory, showing we haven't saved them.
assertFalse(new File(storage, "5-parallel-synthetic.xml").exists());
assertFalse(new File(storage, "6-parallel-synthetic.xml").exists());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class JobAnalyticsTest method createMultiBranch.
private void createMultiBranch(GitSampleRepoRule rule) throws Exception {
WorkflowMultiBranchProject mp = j.createProject(WorkflowMultiBranchProject.class, UUID.randomUUID().toString());
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, rule.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
mp.save();
mp.scheduleBuild2(0).getFuture().get();
mp.getIndexing().getLogText().writeLogTo(0, System.out);
j.waitUntilNoActivity();
WorkflowJob master = mp.getItemByBranchName("master");
assertNotNull(master);
WorkflowRun lastBuild = master.getLastBuild();
assertNotNull(lastBuild);
assertEquals(Result.SUCCESS, lastBuild.getResult());
}
Aggregations