use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method encodedStepDescription.
@Test
public void encodedStepDescription() throws Exception {
setupScm("pipeline {\n" + " agent any\n" + " stages {\n" + " stage('Build') {\n" + " steps {\n" + " sh 'echo \"\\033[32m some text \\033[0m\"' \n" + " }\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(1, stages.size());
Assert.assertEquals("Build", stages.get(0).getDisplayName());
List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertEquals("Build", resp.get(0).get("displayName"));
resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
Assert.assertEquals(2, resp.size());
assertEquals("General SCM", resp.get(0).get("displayName"));
assertEquals("Shell Script", resp.get(1).get("displayName"));
assertEquals("echo \"\u001B[32m some text \u001B[0m\"", resp.get(1).get("displayDescription"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method testNonblockStageSteps.
@Test
public void testNonblockStageSteps() throws Exception {
String pipeline = "node {\n" + " stage 'Checkout'\n" + " echo 'checkingout'\n" + " stage 'Build'\n" + " echo 'building'\n" + " stage 'Archive'\n" + " echo 'archiving...'\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(3, stages.size());
Assert.assertEquals(0, parallels.size());
// TODO: complete test
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(3, resp.size());
String checkoutId = (String) resp.get(0).get("id");
String buildId = (String) resp.get(0).get("id");
String archiveId = (String) resp.get(0).get("id");
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals(3, resp.size());
Assert.assertNotNull(checkoutId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + checkoutId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertNotNull(buildId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + buildId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
Assert.assertNotNull(archiveId);
resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + archiveId + "/steps/", List.class);
Assert.assertEquals(1, resp.size());
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method submitInputPostBlock.
@Test
@Issue("JENKINS-49297")
public void submitInputPostBlock() throws Exception {
WorkflowJob job = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
URL resource = Resources.getResource(getClass(), "stepsFromPost.jenkinsfile");
String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
job.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
QueueTaskFuture<WorkflowRun> buildTask = job.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
List<Map> nodes = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
assertEquals(1, nodes.size());
List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + nodes.get(0).get("id") + "/steps/", List.class);
assertEquals(3, steps.size());
assertEquals("7", steps.get(0).get("id"));
assertEquals("Hello World", steps.get(0).get("displayDescription"));
assertEquals("12", steps.get(1).get("id"));
assertEquals("Hello World from post", steps.get(1).get("displayDescription"));
assertEquals("13", steps.get(2).get("id"));
assertEquals("Wait for interactive input", steps.get(2).get("displayName"));
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineJobRunNodesWithFailureTest.
@Test
public void getPipelineJobRunNodesWithFailureTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("stage 'build'\n" + "node{\n" + " echo \"Building...\"\n" + "}\n" + "\n" + "stage 'test'\n" + "parallel 'unit':{\n" + " node{\n" + " echo \"Unit testing...\"\n" + // fail the build intentionally
" sh \"`fail-the-build`\"\n" + " }\n" + "},'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + "}, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + "}\n" + "\n" + "stage 'deploy'\n" + "node{\n" + " echo \"Deploying\"\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
j.assertBuildStatus(Result.FAILURE, b1);
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(b1);
List<FlowNode> nodes = getStagesAndParallels(builder);
List<FlowNode> parallelNodes = getParallelNodes(builder);
Assert.assertEquals(5, nodes.size());
Assert.assertEquals(3, parallelNodes.size());
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals(nodes.size(), resp.size());
String unitNodeId = null;
for (int i = 0; i < nodes.size(); i++) {
FlowNode n = nodes.get(i);
Map rn = resp.get(i);
Assert.assertEquals(n.getId(), rn.get("id"));
Assert.assertEquals(getNodeName(n), rn.get("displayName"));
List<Map> edges = (List<Map>) rn.get("edges");
if (n.getDisplayName().equals("test")) {
Assert.assertEquals(parallelNodes.size(), edges.size());
Assert.assertEquals(edges.get(i).get("id"), parallelNodes.get(i).getId());
Assert.assertEquals("FAILURE", rn.get("result"));
} else if (n.getDisplayName().equals("build")) {
Assert.assertEquals(1, edges.size());
Assert.assertEquals(edges.get(i).get("id"), nodes.get(i + 1).getId());
Assert.assertEquals("SUCCESS", rn.get("result"));
} else if (n.getDisplayName().equals("Branch: unit")) {
unitNodeId = n.getId();
Assert.assertEquals(0, edges.size());
Assert.assertEquals("FAILURE", rn.get("result"));
} else {
Assert.assertEquals(0, edges.size());
Assert.assertEquals("SUCCESS", rn.get("result"));
}
}
assertNotNull(unitNodeId);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + unitNodeId + "/steps/", List.class);
String log = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + unitNodeId + "/log/", String.class);
assertNotNull(log);
}
use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method getPipelineJobRunNodeNoStageTest.
@Test
public void getPipelineJobRunNodeNoStageTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("node{\n" + " parallel 'unit':{\n" + " node{\n" + " sh \"Unit testing...\"\n" + " }\n" + " },'integration':{\n" + " node{\n" + " echo \"Integration testing...\"\n" + " }\n" + " }, 'ui':{\n" + " node{\n" + " echo \"UI testing...\"\n" + " }\n" + " }\n" + "}"));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
// j.assertBuildStatusSuccess(b1);
// FlowGraphTable nodeGraphTable = new FlowGraphTable(b1.getExecution());
// nodeGraphTable.build();
// List<FlowNode> nodes = getStages(nodeGraphTable);
// List<FlowNode> parallelNodes = getParallelNodes(nodeGraphTable);
//
// Assert.assertEquals(3, nodes.size());
// Assert.assertEquals(3, parallelNodes.size());
//
// // get all nodes for pipeline1
List<Map> resp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/" + resp.get(0).get("id") + "/steps/", List.class);
// Assert.assertEquals(nodes.size(), resp.size());
}
Aggregations