use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testBlockedStep.
@Test
public void testBlockedStep() throws Exception {
String scipt = "node {\n" + " stage(\"one\"){\n" + " echo '1'\n" + " }\n" + " stage(\"two\") {\n" + " node('blah'){\n" + " sh 'blah'\n" + " }\n" + " }\n" + "\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(scipt, false));
QueueTaskFuture<WorkflowRun> runQueueTaskFuture = job1.scheduleBuild2(0);
WorkflowRun run = runQueueTaskFuture.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
if (waitForItemToAppearInQueue(1000 * 300)) {
// 5 min timeout
List<FlowNode> nodes = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run));
if (nodes.size() == 2) {
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/11/steps/", List.class);
assertEquals(1, stepsResp.size());
assertEquals("QUEUED", stepsResp.get(0).get("state"));
}
} else {
// Avoid spurious code coverage failures
final FlowNode node = new FlowNode(null, "fake") {
@Override
protected String getTypeDisplayName() {
return "fake";
}
};
final MemoryFlowChunk chunk = new MemoryFlowChunk() {
@Override
public FlowNode getFirstNode() {
return node;
}
};
new PipelineStepVisitor.LocalAtomNode(chunk, "fake");
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method stepStatusForUnstableBuild.
// JENKINS-39203
@Test
public void stepStatusForUnstableBuild() throws Exception {
String p = "node {\n" + " echo 'Hello World'\n" + " try{\n" + " echo 'Inside try'\n" + " }finally{\n" + " sh 'echo \"blah\"' \n" + " currentBuild.result = \"UNSTABLE\"\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(p));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.UNSTABLE, b1);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(resp.size(), 3);
for (int i = 0; i < resp.size(); i++) {
Map rn = resp.get(i);
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method abortInput.
@Test
public void abortInput() throws Exception {
String script = "node {\n" + " stage(\"thing\"){\n" + " input 'continue'\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);
System.out.println(stepsResp);
Assert.assertEquals("PAUSED", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
String stepId = (String) stepsResp.get(0).get("id");
// Assert.assertEquals("7", stepsResp.get(0).get("id"));
Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).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/" + stepId + "/", req, 200);
if (waitForBuildCount(job1, 1, Result.ABORTED)) {
Map<String, Object> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + stepId + "/");
Assert.assertEquals("FINISHED", resp.get("state"));
Assert.assertEquals("ABORTED", resp.get("result"));
Assert.assertEquals(stepId, resp.get("id"));
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method stepStatusForFailedBuild.
@Test
@Issue("JENKINS-39296")
public void stepStatusForFailedBuild() throws Exception {
String p = "node {\n" + " echo 'Hello World'\n" + " try{\n" + " echo 'Inside try'\n" + " sh 'this should fail'" + " }finally{\n" + " echo 'this should pass'\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(p));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(resp.size(), 4);
Map helloWorldStep = resp.get(0);
Assert.assertEquals("Hello World", helloWorldStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", helloWorldStep.get("result"));
Assert.assertEquals("FINISHED", helloWorldStep.get("state"));
Map insideTryStep = resp.get(1);
Assert.assertEquals("Inside try", insideTryStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", insideTryStep.get("result"));
Assert.assertEquals("FINISHED", insideTryStep.get("state"));
Map thisShouldFailStep = resp.get(2);
Assert.assertEquals("this should fail", thisShouldFailStep.get("displayDescription"));
Assert.assertEquals("FAILURE", thisShouldFailStep.get("result"));
Assert.assertEquals("FINISHED", thisShouldFailStep.get("state"));
Map thisShouldPassStep = resp.get(3);
Assert.assertEquals("this should pass", thisShouldPassStep.get("displayDescription"));
Assert.assertEquals("SUCCESS", thisShouldPassStep.get("result"));
Assert.assertEquals("FINISHED", thisShouldPassStep.get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method submitInput.
@Test
public void submitInput() throws Exception {
String script = "node {\n" + " stage(\"first\"){\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" + "}";
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("PAUSED", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("7", stepsResp.get(0).get("id"));
Map<String, Object> input = (Map<String, Object>) stepsResp.get(0).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/7/", 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/7/");
Assert.assertEquals("FINISHED", resp.get("state"));
Assert.assertEquals("SUCCESS", resp.get("result"));
Assert.assertEquals("7", resp.get("id"));
}
}
Aggregations