use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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" + " }", false));
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.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method singleStageSequentialLastInParallel.
@Test
@Issue("JENKINS-53900")
public void singleStageSequentialLastInParallel() throws Exception {
final String jenkinsfile = "pipeline {\n" + " agent any\n" + " stages {\n" + " stage('Alpha') {\n" + " parallel {\n" + " stage('Blue') {\n" + " steps {\n" + " script {\n" + " println \"XXXX\"\n" + " }\n" + " }\n" + " }\n" + " stage('Red') {\n" + " stages {\n" + " stage('Green') {\n" + " steps {\n" + " script {\n" + " println \"XXXX\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " stage('Bravo') {\n" + " steps {\n" + " script {\n" + " println \"XXXX\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + "}\n";
WorkflowJob project1 = j.createProject(WorkflowJob.class, "project1");
project1.setDefinition(new CpsFlowDefinition(jenkinsfile, true));
j.assertBuildStatus(Result.SUCCESS, project1.scheduleBuild2(0));
WorkflowRun r = project1.getLastBuild();
List<Map> resp = get("/organizations/jenkins/pipelines/project1/runs/" + r.getId() + "/nodes/", List.class);
assertEquals("number of nodes", 5, resp.size());
final Map<String, Object> bravoNode = resp.get(3);
final Map<String, Object> greenNode = resp.get(4);
assertEquals("includes Alpha node", "Alpha", resp.get(0).get("displayName"));
assertEquals("includes Blue node", "Blue", resp.get(1).get("displayName"));
assertEquals("includes Red node", "Red", resp.get(2).get("displayName"));
assertEquals("includes Bravo node", "Bravo", bravoNode.get("displayName"));
assertEquals("includes Green node", "Green", greenNode.get("displayName"));
String bravoId = bravoNode.get("id").toString();
List<Map<String, Object>> greenEdges = (List<Map<String, Object>>) greenNode.get("edges");
assertEquals("green has edges", 1, greenEdges.size());
assertEquals("green has edge pointing to bravo", bravoId, greenEdges.get(0).get("id"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method downstreamBuildLinksDeclarative.
@Test
@Issue("JENKINS-38339")
public void downstreamBuildLinksDeclarative() throws Exception {
FreeStyleProject downstream1 = j.createFreeStyleProject("downstream1");
FreeStyleProject downstream2 = j.createFreeStyleProject("downstream2");
WorkflowJob upstream = j.createProject(WorkflowJob.class, "upstream");
URL resource = getClass().getResource("downstreamBuildLinksDecl.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.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.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method submitInputPostBlock.
@Test
@Issue("JENKINS-49297")
public void submitInputPostBlock() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
URL resource = getClass().getResource("stepsFromPost.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
assertEquals(1, nodes.size());
List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(0).get("id") + "/steps/", List.class);
assertEquals(3, steps.size());
assertEquals("7", steps.get(0).get("id"));
assertEquals("Hello World", steps.get(0).get("displayDescription"));
assertEquals("12", steps.get(1).get("id"));
assertEquals("Hello World from post", steps.get(1).get("displayDescription"));
assertEquals("13", steps.get(2).get("id"));
assertEquals("Wait for interactive input", steps.get(2).get("displayName"));
}
Aggregations