use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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(Arrays.asList("2", "3", "4", "5", "6", "8"), new PipelineEventListener().getBranch(parallels.get(0)));
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class LinkResolverTest method nestedFolderJobLinkResolveTest.
@Test
public void nestedFolderJobLinkResolveTest() throws IOException {
Project f = j.createFreeStyleProject("fstyle1");
MockFolder folder1 = j.createFolder("folder1");
Project p1 = folder1.createProject(FreeStyleProject.class, "test1");
MockFolder folder2 = folder1.createProject(MockFolder.class, "folder2");
MockFolder folder3 = folder2.createProject(MockFolder.class, "folder3");
Project p2 = folder2.createProject(FreeStyleProject.class, "test2");
Project p3 = folder3.createProject(FreeStyleProject.class, "test3");
WorkflowJob pipelineJob1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
pipelineJob1.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "\n"));
WorkflowJob pipelineJob2 = folder2.createProject(WorkflowJob.class, "pipeline2");
pipelineJob2.setDefinition(new CpsFlowDefinition("stage \"Build\"\n" + " node {\n" + " sh \"echo here\"\n" + " }\n" + "\n"));
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/pipeline1/", LinkResolver.resolveLink(pipelineJob1).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/pipeline2/", LinkResolver.resolveLink(pipelineJob2).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/fstyle1/", LinkResolver.resolveLink(f).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/", LinkResolver.resolveLink(folder1).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/test1/", LinkResolver.resolveLink(p1).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/", LinkResolver.resolveLink(folder2).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/test2/", LinkResolver.resolveLink(p2).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/", LinkResolver.resolveLink(folder3).getHref());
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/folder2/pipelines/folder3/pipelines/test3/", LinkResolver.resolveLink(p3).getHref());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineBaseTest method createWorkflowJobWithJenkinsfile.
protected WorkflowJob createWorkflowJobWithJenkinsfile(Class<?> contextClass, String jenkinsFileName) throws java.io.IOException {
WorkflowJob p = j.createProject(WorkflowJob.class, "project-" + UUID.randomUUID());
URL resource = contextClass.getResource(jenkinsFileName);
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
p.save();
return p;
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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" + "}", false));
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());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method waitForInputTest.
@Test
public void waitForInputTest() throws Exception {
String script = "node {\n" + " stage(\"parallelStage\"){\n" + " parallel left : {\n" + " echo \"running\"\n" + " def branchInput = input message: 'Please input branch to test against', parameters: [[$class: 'StringParameterDefinition', defaultValue: 'master', description: '', name: 'branch']]\n" + " echo \"BRANCH NAME: ${branchInput}\"\n" + " }, \n" + " right : {\n" + " sh 'sleep 100000'\n" + " }\n" + " }\n" + "}";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script, false));
QueueTaskFuture<WorkflowRun> buildTask = job1.scheduleBuild2(0);
WorkflowRun run = buildTask.getStartCondition().get();
CpsFlowExecution e = (CpsFlowExecution) run.getExecutionPromise().get();
while (run.getAction(InputAction.class) == null) {
e.waitForSuspension();
}
Map runResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/");
Assert.assertEquals("PAUSED", runResp.get("state"));
List<FlowNodeWrapper> nodes = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(run).getPipelineNodes();
List<Map> nodesResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/nodes/", List.class);
Assert.assertEquals("PAUSED", nodesResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(0).get("result"));
Assert.assertEquals("parallelStage", nodesResp.get(0).get("displayName"));
Assert.assertEquals("PAUSED", nodesResp.get(1).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(1).get("result"));
Assert.assertEquals("left", nodesResp.get(1).get("displayName"));
Assert.assertEquals("RUNNING", nodesResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", nodesResp.get(2).get("result"));
Assert.assertEquals("right", nodesResp.get(2).get("displayName"));
List<Map> stepsResp = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
Assert.assertEquals("RUNNING", stepsResp.get(0).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(0).get("result"));
Assert.assertEquals("13", stepsResp.get(0).get("id"));
Assert.assertEquals("PAUSED", stepsResp.get(2).get("state"));
Assert.assertEquals("UNKNOWN", stepsResp.get(2).get("result"));
Assert.assertEquals("12", stepsResp.get(2).get("id"));
}
Aggregations