use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testTestsInStage.
@Test
public void testTestsInStage() throws Exception {
String pipeline = "" + "node {\n" + " stage ('dev') {\n" + " junit('*.xml')\n" + " }\n" + " stage ('prod') {\n" + " junit('*.xml')\n" + " }\n" + " stage ('testing') {\n" + " parallel(first: {\n" + " junit('*.xml')\n" + " },\n" + " second: {\n" + " junit('*.xml')\n" + " })\n" + " }\n" + "}\n";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(pipeline, true));
FilePath ws = j.jenkins.getWorkspaceFor(job1);
FilePath testFile = ws.child("test-result.xml");
testFile.copyFrom(PipelineNodeTest.class.getResource("testResult.xml"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> stages = getStages(builder);
Assert.assertEquals(3, stages.size());
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(5, resp.size());
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/tests/", List.class);
Assert.assertEquals(4, resp.size());
Assert.assertEquals("dev / testDummyMethod – DummyTest", resp.get(0).get("name"));
Assert.assertEquals("prod / testDummyMethod – DummyTest", resp.get(1).get("name"));
Assert.assertEquals("testing / first / testDummyMethod – DummyTest", resp.get(2).get("name"));
Assert.assertEquals("testing / second / testDummyMethod – DummyTest", resp.get(3).get("name"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testDynamicInnerStage.
@Test
public void testDynamicInnerStage() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "p");
URL resource = Resources.getResource(getClass(), "testDynamicInnerStage.jenkinsfile");
String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
WorkflowRun build = job.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, build);
List<Map> nodes = get("/organizations/jenkins/pipelines/p/runs/1/nodes/", List.class);
assertEquals(4, nodes.size());
assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(0).get("type"));
assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(1).get("type"));
assertEquals(FlowNodeWrapper.NodeType.PARALLEL.name(), nodes.get(2).get("type"));
assertEquals(FlowNodeWrapper.NodeType.STAGE.name(), nodes.get(3).get("type"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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.WorkflowJob 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.WorkflowJob 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"));
}
}
Aggregations