use of org.jenkinsci.plugins.workflow.cps.CpsFlowExecution in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method waitForInputTest.
@Test
public void waitForInputTest() throws Exception {
String script = "node {\n" + " stage(\"parallelStage\"){\n" + " parallel left : {\n" + " echo \"running\"\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }, \n" + " right : {\n" + " sh 'sleep 100000'\n" + " }\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
Map runResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/");
Assert.assertEquals("PAUSED", runResp.get("state"));
List<FlowNodeWrapper> nodes = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run).getPipelineNodes();
List<Map> nodesResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals("PAUSED", nodesResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(0).get("result"));
Assert.assertEquals("parallelStage", nodesResp.get(0).get("displayName"));
Assert.assertEquals("PAUSED", nodesResp.get(1).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(1).get("result"));
Assert.assertEquals("left", nodesResp.get(1).get("displayName"));
Assert.assertEquals("RUNNING", nodesResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(2).get("result"));
Assert.assertEquals("right", nodesResp.get(2).get("displayName"));
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals("RUNNING", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("13", stepsResp.get(0).get("id"));
Assert.assertEquals("PAUSED", stepsResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(2).get("result"));
Assert.assertEquals("12", stepsResp.get(2).get("id"));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowExecution in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method abortInput.
@Test
public void abortInput() throws Exception {
String script = "node {\n" + " stage(\"parallelStage\"){\n" + " parallel left : {\n" + " echo \"running\"\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }, \n" + " right : {\n" + " sh 'echo 'right done''\n" + " }\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals("RUNNING", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("13", stepsResp.get(0).get("id"));
Assert.assertEquals("PAUSED", stepsResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(2).get("result"));
Assert.assertEquals("12", stepsResp.get(2).get("id"));
Map<String, Object> input = (Map<String, Object>) stepsResp.get(2).get("input");
Assert.assertNotNull(input);
String id = (String) input.get("id");
Assert.assertNotNull(id);
JSONObject req = new JSONObject();
req.put("id", id);
req.put("abort", true);
post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/12/", req, 200);
if (waitForBuildCount(job1, 1, Result.ABORTED)) {
Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/12/");
Assert.assertEquals("FINISHED", resp.get("state"));
Assert.assertEquals("ABORTED", resp.get("result"));
Assert.assertEquals("12", resp.get("id"));
}
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowExecution in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method submitInput.
@Test
public void submitInput() throws Exception {
String script = "node {\n" + " stage(\"parallelStage\"){\n" + " parallel left : {\n" + " echo \"running\"\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }, \n" + " right : {\n" + " sh 'echo \"right done\"'\n" + " }\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals("RUNNING", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("13", stepsResp.get(0).get("id"));
Assert.assertEquals("PAUSED", stepsResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(2).get("result"));
Assert.assertEquals("12", stepsResp.get(2).get("id"));
Map<String, Object> input = (Map<String, Object>) stepsResp.get(2).get("input");
Assert.assertNotNull(input);
String id = (String) input.get("id");
Assert.assertNotNull(id);
List<Map<String, Object>> params = (List<Map<String, Object>>) input.get("parameters");
post("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/12/", ImmutableMap.of("id", id, PARAMETERS_ELEMENT, ImmutableList.of(ImmutableMap.of("name", params.get(0).get("name"), "value", "master"))), 200);
if (waitForBuildCount(job1, 1, Result.SUCCESS)) {
Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/12/");
Assert.assertEquals("FINISHED", resp.get("state"));
Assert.assertEquals("SUCCESS", resp.get("result"));
Assert.assertEquals("12", resp.get("id"));
}
}
Aggregations