use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineBaseTest method findBranchProject.
protected WorkflowJob findBranchProject(WorkflowMultiBranchProject mp, String name) throws Exception {
WorkflowJob p = mp.getItem(name);
if (p == null) {
mp.getIndexing().writeWholeLogTo(System.out);
fail(name + " project not found");
}
return p;
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineBaseTest method validatePipeline.
protected void validatePipeline(Job p, Map resp) {
Assert.assertEquals("jenkins", resp.get("organization"));
Assert.assertEquals(p.getName(), resp.get("name"));
Assert.assertEquals(p.getDisplayName(), resp.get("displayName"));
Assert.assertEquals(p.getFullName(), resp.get("fullName"));
Assert.assertEquals(p.getBuildHealth().getScore(), resp.get("weatherScore"));
if (p.getLastSuccessfulBuild() != null) {
Run b = p.getLastSuccessfulBuild();
String s = baseUrl + "/organizations/jenkins/pipelines/" + p.getName() + "/runs/" + b.getId() + "/";
if (p instanceof WorkflowJob && p.getParent() instanceof MultiBranchProject) {
s = baseUrl + "/organizations/jenkins/pipelines/" + ((MultiBranchProject) p.getParent()).getName() + "/branches/" + Util.rawEncode(p.getName()) + "/runs/" + b.getId() + "/";
}
Assert.assertEquals(s, resp.get("lastSuccessfulRun"));
} else {
Assert.assertNull(resp.get("lastSuccessfulRun"));
}
if (p.getLastBuild() != null) {
Run r = p.getLastBuild();
validateRun(r, (Map) resp.get("latestRun"), "FINISHED");
} else {
Assert.assertNull(resp.get("latestRun"));
}
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineWihoutNodesAllStepsTest.
@Test
public void getPipelineWihoutNodesAllStepsTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " sh \"echo Building...\"\n" + "}\n" + " node{\n" + " echo \"Unit testing...\"\n" + " sh \"echo Tests running\"\n" + " sh \"echo Tests completed\"\n" + " }"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(4, resp.size());
String log = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/" + resp.get(0).get("id") + "/log/", String.class);
assertNotNull(log);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method declarativeSyntheticSteps.
@Test
public void declarativeSyntheticSteps() throws Exception {
setupScm("pipeline {\n" + " agent any\n" + " stages {\n" + " stage(\"build\") {\n" + " steps{\n" + " sh 'echo \"Start Build\"'\n" + " echo 'End Build'\n" + " }\n" + " }\n" + " stage(\"deploy\") {\n" + " steps{\n" + " sh 'echo \"Start Deploy\"'\n" + " sh 'echo \"Deploying...\"'\n" + " sh 'echo \"End Deploy\"'\n" + " } \n" + " }\n" + " }\n" + " post {\n" + " failure {\n" + " echo \"failed\"\n" + " }\n" + " success {\n" + " echo \"success\"\n" + " }\n" + " }\n" + "}");
WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false)));
for (SCMSource source : mp.getSCMSources()) {
assertEquals(mp, source.getOwner());
}
mp.scheduleBuild2(0).getFuture().get();
j.waitUntilNoActivity();
WorkflowJob p = scheduleAndFindBranchProject(mp, "master");
j.waitUntilNoActivity();
WorkflowRun b1 = p.getLastBuild();
Assert.assertEquals(Result.SUCCESS, b1.getResult());
List<FlowNode> stages = getStages(NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1));
Assert.assertEquals(2, stages.size());
Assert.assertEquals("build", stages.get(0).getDisplayName());
Assert.assertEquals("deploy", stages.get(1).getDisplayName());
List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
Assert.assertEquals(2, resp.size());
Assert.assertEquals("build", resp.get(0).get("displayName"));
Assert.assertEquals("deploy", resp.get(1).get("displayName"));
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
Assert.assertEquals(7, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
Assert.assertEquals(3, resp.size());
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
Assert.assertEquals(4, resp.size());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testBlockStage.
@Test
public void testBlockStage() throws Exception {
String pipeline = "" + "node {" + //start
" stage ('dev');" + " echo ('development'); " + " stage ('Build') { " + " echo ('Building'); " + " } \n" + " stage ('test') { " + " echo ('Testing'); " + //1
" parallel firstBranch: {\n" + " echo 'first Branch'\n" + " sh 'sleep 1'\n" + " echo 'first Branch end'\n" + " }, secondBranch: {\n" + " echo 'Hello second Branch'\n" + " sh 'sleep 1' \n" + " echo 'second Branch end'\n" + " \n" + " },\n" + " failFast: false\n" + " } \n" + " stage ('deploy') { " + " writeFile file: 'file.txt', text:'content'; " + " archive(includes: 'file.txt'); " + " echo ('Deploying'); " + " } \n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(pipeline));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> stages = getStages(builder);
List<FlowNode> parallels = getParallelNodes(builder);
;
Assert.assertEquals(4, stages.size());
Assert.assertEquals(2, parallels.size());
//TODO: complete test
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(6, resp.size());
String testStageId = null;
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("dev")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("test")) {
testStageId = (String) rn.get("id");
Assert.assertEquals(2, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("firstBranch")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("secondBranch")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
} else if (rn.get("displayName").equals("deploy")) {
Assert.assertEquals(0, edges.size());
Assert.assertEquals(rn.get("result"), "SUCCESS");
Assert.assertEquals(rn.get("state"), "FINISHED");
}
}
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(12, resp.size());
Assert.assertNotNull(testStageId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + testStageId + "/steps/", List.class);
Assert.assertEquals(7, resp.size());
}
Aggregations