use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineRunblockingStopTest.
// TODO: Fix test - see JENKINS-38319
@Test
@Ignore
public void getPipelineRunblockingStopTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build1'); " + " sh('sleep 60') " + " stage ('Test1'); " + " echo ('Testing'); " + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
Map r = // default timeOutInSecs=10 sec
request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop/?blocking=true").build(Map.class);
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b1);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineFailingActionTest.
@Test
public void getPipelineFailingActionTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
WorkflowJob job2 = j.jenkins.createProject(WorkflowJob.class, "pipeline2");
String script = "\n" + "node {\n" + " stage ('Build'){ \n" + " echo ('Building'); \n" + " } \n" + " stage ('Test') { \n" + " echo ('Testing'); \n" + " } \n" + "}";
job1.setDefinition(new CpsFlowDefinition(script));
job1.addAction(new ExplodingAction());
job1.addAction(new TestAction());
job2.setDefinition(new CpsFlowDefinition(script));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
b1.addAction(new ExplodingAction());
b1.addAction(new TestAction());
WorkflowRun b2 = job2.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b2);
List<Map> pipelines = get("/organizations/jenkins/pipelines/?tree=*[*]", List.class);
Assert.assertEquals(2, pipelines.size());
validateBrokenAction((List<Map>) pipelines.get(0).get("actions"));
Map pipeline = get("/organizations/jenkins/pipelines/pipeline1/?tree=*[*]");
validatePipeline(job1, pipeline);
validateBrokenAction((List<Map>) pipeline.get("actions"));
List<Map> runs = get("/organizations/jenkins/pipelines/pipeline1/runs/?tree=*[*]", List.class);
Assert.assertEquals(1, runs.size());
validateBrokenAction((List<Map>) pipelines.get(0).get("actions"));
Map resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/?tree=*[*]");
validateBrokenAction((List<Map>) resp.get("actions"));
validateRun(b1, resp);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineEventListenerTest method testParentNodesOrder.
@Test
public void testParentNodesOrder() throws Exception {
String script = "node {\n" + " stage('one') {\n" + " sh \"echo 42\" \n" + " parallel('branch1':{\n" + " sh 'echo \"branch1\"'\n" + " }, 'branch2': {\n" + " sh 'echo \"branch2\"'\n" + " })\n" + " }\n" + "\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
List<FlowNode> parallels = getParallelNodes(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
Assert.assertEquals("10", parallels.get(0).getId());
Assert.assertEquals("Branch: branch1", parallels.get(0).getDisplayName());
Assert.assertEquals(Lists.newArrayList("2", "3", "4", "5", "6", "8"), new PipelineEventListener().getBranch(parallels.get(0)));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class SseEventTest method multiBranchJobEventsWithCustomOrg.
@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
MockFolder folder = j.createFolder("TestOrgFolderName");
assertNotNull(folder);
setupScm();
final OneShotEvent success = new OneShotEvent();
final Boolean[] pipelineNameMatched = { null };
final Boolean[] mbpPipelineNameMatched = { null };
SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
@Override
public void onMessage(@Nonnull Message message) {
System.out.println(message);
if ("job".equals(message.get(jenkins_channel))) {
if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
mbpPipelineNameMatched[0] = true;
} else {
mbpPipelineNameMatched[0] = false;
}
} else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
pipelineNameMatched[0] = true;
} else {
pipelineNameMatched[0] = false;
}
}
}
if (pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null) {
success.signal();
}
}
});
con.subscribe("pipeline");
con.subscribe("job");
final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
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();
WorkflowJob p = mp.getItem("master");
if (p == null) {
mp.getIndexing().writeWholeLogTo(System.out);
fail("master project not found");
}
j.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
assertEquals(2, mp.getItems().size());
success.block(5000);
con.close();
if (success.isSignaled()) {
assertTrue(pipelineNameMatched[0]);
assertTrue(mbpPipelineNameMatched[0]);
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowRun in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageStepsWithDesc.
@Test
public void BlockStageStepsWithDesc() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " stage ('Build') {\n" + " sh 'echo \"Building\"'\n" + " }\n" + " stage ('Test') {\n" + " sh 'echo testing'\n" + " }\n" + " stage ('Deploy') {\n" + " sh 'echo deploy'\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.SUCCESS, b1);
List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(3, steps.size());
Assert.assertEquals("Shell Script", steps.get(0).get("displayName"));
Assert.assertEquals("Shell Script", steps.get(1).get("displayName"));
Assert.assertEquals("Shell Script", steps.get(2).get("displayName"));
Assert.assertEquals("echo \"Building\"", steps.get(0).get("displayDescription"));
Assert.assertEquals("echo testing", steps.get(1).get("displayDescription"));
Assert.assertEquals("echo deploy", steps.get(2).get("displayDescription"));
}
Aggregations