use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method queuedSingleNode.
@Issue("JENKINS-44981")
@Test
public void queuedSingleNode() throws Exception {
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "queuedSingleNode.jenkinsfile");
// Ensure null before first run
Map pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
Assert.assertNull(pipeline.get("latestRun"));
// Run until completed
WorkflowRun r = p.scheduleBuild2(0).waitForStart();
j.waitForMessage("Still waiting to schedule task", r);
// Get latest run for this pipeline
pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
Map latestRun = (Map) pipeline.get("latestRun");
Assert.assertEquals("QUEUED", latestRun.get("state"));
Assert.assertEquals("1", latestRun.get("id"));
Assert.assertEquals("Jenkins doesn’t have label test", latestRun.get("causeOfBlockage"));
j.createOnlineSlave(Label.get("test"));
j.assertBuildStatusSuccess(j.waitForCompletion(r));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method declarativeQueuedAgent.
@Issue("JENKINS-44981")
@Test
public void declarativeQueuedAgent() throws Exception {
WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), "declarativeQueuedAgent.jenkinsfile");
j.jenkins.setNumExecutors(0);
// Ensure null before first run
Map pipeline = request().get(String.format("/organizations/jenkins/pipelines/%s/", p.getName())).build(Map.class);
Assert.assertNull(pipeline.get("latestRun"));
// Run until completed
WorkflowRun r = p.scheduleBuild2(0).waitForStart();
j.waitForMessage("Still waiting to schedule task", r);
// Get latest run for this pipeline
String url = String.format("/organizations/jenkins/pipelines/%s/runs/%s/", p.getName(), r.getId());
Map latestRun = request().get(url).build(Map.class);
Assert.assertEquals("QUEUED", latestRun.get("state"));
Assert.assertEquals("1", latestRun.get("id"));
Assert.assertEquals("Waiting for next available executor", latestRun.get("causeOfBlockage"));
j.jenkins.setNumExecutors(2);
j.assertBuildStatusSuccess(j.waitForCompletion(r));
// Disable the executors.
j.jenkins.setNumExecutors(0);
// Run until we hang.
WorkflowRun r2 = p.scheduleBuild2(0).waitForStart();
j.waitForMessage("Still waiting to schedule task", r2);
// Get latest run for this pipeline
url = String.format("/organizations/jenkins/pipelines/%s/runs/%s/", p.getName(), r2.getId());
latestRun = request().get(url).build(Map.class);
Assert.assertEquals("2", latestRun.get("id"));
Assert.assertEquals("QUEUED", latestRun.get("state"));
Assert.assertEquals("Waiting for next available executor", latestRun.get("causeOfBlockage"));
j.jenkins.setNumExecutors(2);
j.assertBuildStatusSuccess(j.waitForCompletion(r2));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class AbstractRunImplTest method replayRunTest.
// Disabled, see JENKINS-36453
@Test
@Ignore
public void replayRunTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
j.createOnlineSlave(Label.get("remote"));
job1.setDefinition(new CpsFlowDefinition("node('remote') {\n" + " ws {\n" + " git($/" + sampleRepo + "/$)\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
sampleRepo.write("file1", "");
sampleRepo.git("add", "file1");
sampleRepo.git("commit", "--message=init");
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
Assert.assertNotEquals(new PipelineRunImpl(b1, null, null).getCommitId(), new PipelineRunImpl(b2, null, null).getCommitId());
request().post("/organizations/jenkins/pipelines/pipeline1/runs/1/replay").build(String.class);
j.waitForCompletion(job1.getLastBuild());
Map r = request().get("/organizations/jenkins/pipelines/pipeline1/runs/3/").build(Map.class);
assertEquals(r.get("commitId"), new PipelineRunImpl(b2, null, null).getCommitId());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method testMbpPagination.
@Test
public void testMbpPagination() throws Exception {
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
mp.scheduleBuild2(0).getFuture().get();
this.j.waitUntilNoActivity();
// create 6 runs
List<WorkflowRun> launchedItems = new ArrayList<>();
for (String branch : branches) {
WorkflowJob job = findBranchProject(mp, branch);
launchedItems.addAll(job.getBuilds());
for (int j = 0; j < 2; j++) {
launchedItems.add(job.scheduleBuild2(0).waitForStart());
this.j.waitUntilNoActivity();
}
}
// total 9. 3 triggered from indexing and 6 we launched
assertEquals(9, launchedItems.size());
// sort runs
Collections.sort(launchedItems, new Comparator<WorkflowRun>() {
@Override
public int compare(WorkflowRun o1, WorkflowRun o2) {
return new Date(o2.getStartTimeInMillis()).compareTo(new Date(o1.getStartTimeInMillis()));
}
});
// request 10 runs, but should not return 9 runs.
List<Map> resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=10", List.class);
// max number of runs are 9
assertEquals(9, resp.size());
for (int i = 0; i < 9; i++) {
Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
}
// now call 3 out of 9 runs and see pagination returns only 3 and in right sort order
resp = get("/organizations/jenkins/pipelines/p/runs?start=0&limit=3", List.class);
assertEquals(3, resp.size());
for (int i = 0; i < 3; i++) {
Assert.assertEquals(launchedItems.get(i).getId(), (resp.get(i).get("id")));
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineRunStopTest.
@Test
public void getPipelineRunStopTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build'); " + " semaphore 's' " + " stage ('Test'); " + " echo ('Testing'); " + "}", false));
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("s/1", b1);
Map r = null;
for (int i = 0; i < 10; i++) {
r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b1);
FreeStyleProject p = j.createFreeStyleProject("pipeline5");
p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
for (int i = 0; i < 10; i++) {
r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b2);
}
Aggregations