use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method countBuilds.
private static int countBuilds(WorkflowJob job, Result status) {
RunList<WorkflowRun> builds = job.getNewBuilds();
Iterator<WorkflowRun> iterator = builds.iterator();
int numBuilds = 0;
while (iterator.hasNext()) {
WorkflowRun build = iterator.next();
Result buildRes = build.getResult();
if (status == null || buildRes == status) {
numBuilds++;
}
}
return numBuilds;
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method stageTestJENKINS_40135.
@Test
public void stageTestJENKINS_40135() throws Exception {
String script = "node {\n" + " stage 'Stage 1'\n" + " stage 'Stage 2'\n" + " echo 'hello'\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(2, nodes.size());
Assert.assertEquals("SUCCESS", nodes.get(0).get("result"));
Assert.assertEquals("FINISHED", nodes.get(0).get("state"));
Assert.assertEquals("SUCCESS", nodes.get(1).get("result"));
Assert.assertEquals("FINISHED", nodes.get(1).get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineJobRunsTest.
@Test
public void getPipelineJobRunsTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " echo ('Testing'); " + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
Run[] runs = { b2, b1 };
List<Map> runResponses = get("/organizations/jenkins/pipelines/pipeline1/runs", List.class);
for (int i = 0; i < runs.length; i++) {
validateRun(runs[i], runResponses.get(i));
}
;
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineJobRunsLogTest.
@Test
public void getPipelineJobRunsLogTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " echo ('Building'); " + " stage ('Test1'); " + " echo ('Testing'); " + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
HttpResponse<String> response = get("/organizations/jenkins/pipelines/pipeline1/runs/" + b1.getId() + "/log?start=0", 200, "text/html", HttpResponse.class);
AcceptHeader acceptHeader = new AcceptHeader(response.getHeaders().getFirst("Content-Type"));
Assert.assertNotNull(acceptHeader.select("text/plain"));
int size = Integer.parseInt(response.getHeaders().getFirst("X-Text-Size"));
System.out.println(response.getBody());
Assert.assertTrue(size > 0);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodesWithPartialParallels.
@Test
public void nodesWithPartialParallels() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node {\n" + " stage \"hey\"\n" + " sh \"echo yeah\"\n" + " \n" + " stage \"par\"\n" + " \n" + " parallel left : {\n" + " sh \"echo OMG BS\"\n" + " sh \"echo yeah\"\n" + " }, \n" + " \n" + " right : {\n" + " sh \"echo wozzle\"\n" + " }\n" + " \n" + " stage \"ho\"\n" + " sh \"echo done\"\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
Thread.sleep(1000);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(5, resp.size());
job1.setDefinition(new CpsFlowDefinition("node {\n" + " stage \"hey\"\n" + " sh \"echo yeah\"\n" + " \n" + " stage \"par\"\n" + " \n" + " parallel left : {\n" + " sh \"echo OMG BS\"\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" + " sh \"echo yeah\"\n" + " }, \n" + " \n" + " right : {\n" + " sh \"echo wozzle\"\n" + " def branchInput = input message: 'MF Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }\n" + " \n" + " stage \"ho\"\n" + " sh \"echo done\"\n" + "}"));
job1.scheduleBuild2(0);
Thread.sleep(1000);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/", List.class);
Assert.assertEquals(5, resp.size());
Map leftNode = resp.get(2);
Assert.assertEquals("left", leftNode.get("displayName"));
Map rightNode = resp.get(3);
Assert.assertEquals("right", rightNode.get("displayName"));
List<Map> leftSteps = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/" + leftNode.get("id") + "/steps/", List.class);
Assert.assertEquals(3, leftSteps.size());
List<Map> rightSteps = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/" + rightNode.get("id") + "/steps/", List.class);
Assert.assertEquals(2, rightSteps.size());
}
Aggregations