use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method BlockStageNodesFailureTest3.
@Test
public void BlockStageNodesFailureTest3() 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 'echo1 deploy'\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(3, 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"));
Assert.assertEquals("FAILURE", nodes.get(2).get("result"));
Assert.assertEquals("FINISHED", nodes.get(2).get("state"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method nodesFailureTest.
@Test
public void nodesFailureTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "\n" + "stage \"Test\"\n" + " parallel (\n" + " \"Firefox\" : {\n" + " node {\n" + " sh \"echo ffox\"\n" + " }\n" + " },\n" + " \"Chrome\" : {\n" + " node {\n" + " sh \"echo chrome\"\n" + " }\n" + " }\n" + " )\n" + "\n" + "stage \"CrashyMcgee\"\n" + " parallel (\n" + " \"SlowButSuccess\" : {\n" + " node {\n" + " echo 'This is time well spent.'\n" + " }\n" + " },\n" + " \"DelayThenFail\" : {\n" + " node {\n" + " echo 'Not yet.'\n" + " }\n" + " }\n" + " )\n" + "\n" + "\n" + "stage \"Deploy\"\n" + " node {\n" + " sh \"echo deploying\"\n" + " }"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
job1.setDefinition(new CpsFlowDefinition("throw stage \"Build\"\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "\n" + "stage \"Test\"\n" + " parallel (\n" + " \"Firefox\" : {\n" + " node {\n" + " sh \"echo ffox\"\n" + " }\n" + " },\n" + " \"Chrome\" : {\n" + " node {\n" + " sh \"echo chrome\"\n" + " }\n" + " }\n" + " )\n" + "\n" + "stage \"CrashyMcgee\"\n" + " parallel (\n" + " \"SlowButSuccess\" : {\n" + " node {\n" + " echo 'This is time well spent.'\n" + " }\n" + " },\n" + " \"DelayThenFail\" : {\n" + " node {\n" + " echo 'Not yet.'\n" + " }\n" + " }\n" + " )\n" + "\n" + "\n" + "stage \"Deploy\"\n" + " node {\n" + " sh \"echo deploying\"\n" + " }"));
job1.scheduleBuild2(0);
WorkflowRun b2 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b2);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/2/nodes/", List.class);
Assert.assertEquals(8, resp.size());
for (int i = 0; i < resp.size(); i++) {
Map rn = resp.get(i);
List<Map> edges = (List<Map>) rn.get("edges");
if (rn.get("displayName").equals("Test")) {
Assert.assertEquals(2, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Firefox")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Chrome")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("CrashyMcgee")) {
Assert.assertEquals(2, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("SlowButSuccess")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("DelayThenFail")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
} else if (rn.get("displayName").equals("Deploy")) {
Assert.assertEquals(0, edges.size());
Assert.assertNull(rn.get("result"));
Assert.assertNull(rn.get("state"));
}
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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.WorkflowJob in project blueocean-plugin by jenkinsci.
the class MultiBranchTest method getPipelineJobActivities.
//Disabled test for now as I can't get it to work. Tested manually.
//@Test
public void getPipelineJobActivities() throws Exception {
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
sampleRepo1.init();
sampleRepo1.write("Jenkinsfile", "stage 'build'\n " + "node {echo 'Building'}\n" + "stage 'test'\nnode { echo 'Testing'}\n" + "sleep 10000 \n" + "stage 'deploy'\nnode { echo 'Deploying'}\n");
sampleRepo1.write("file", "initial content");
sampleRepo1.git("add", "Jenkinsfile");
sampleRepo1.git("commit", "--all", "--message=flow");
//create feature branch
sampleRepo1.git("checkout", "-b", "abc");
sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; " + "node {" + " stage ('Build'); " + " echo ('Building'); " + " stage ('Test'); sleep 10000; " + " echo ('Testing'); " + " stage ('Deploy'); " + " echo ('Deploying'); " + "}");
ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
sampleRepo1.write("file", "subsequent content1");
sampleRepo1.git("commit", "--all", "--message=tweaked1");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
scheduleAndFindBranchProject(mp);
for (WorkflowJob job : mp.getItems()) {
Queue.Item item = job.getQueueItem();
if (item != null) {
item.getFuture().waitForStart();
}
job.setConcurrentBuild(false);
job.scheduleBuild2(0);
job.scheduleBuild2(0);
}
List l = request().get("/organizations/jenkins/pipelines/p/activities").build(List.class);
Assert.assertEquals(4, l.size());
Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(2)).get("_class"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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));
}
;
}
Aggregations