use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineNodeTest method orphanParallels1.
@Test
public void orphanParallels1() throws Exception {
String script = "parallel('branch1':{\n" + " node {\n" + " stage('Setup') {\n" + " sh 'echo \"Setup...\"'\n" + " }\n" + " stage('Unit and Integration Tests') {\n" + " sh 'echo \"Unit and Integration Tests...\"'\n" + " }\n" + " }\n" + "}, 'branch2': {\n" + " node {\n" + " stage('Setup') {\n" + " sh 'echo \"Branch2 setup...\"'\n" + " }\n" + " stage('Unit and Integration Tests') {\n" + " echo '\"my command to execute tests\"'\n" + " }\n" + " }\n" + "})";
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition(script, false));
WorkflowRun b1 = job1.scheduleBuild2(0).get();
WorkflowRun run = j.waitForCompletion(b1);
j.assertBuildStatus(Result.SUCCESS, run);
PipelineNodeGraphVisitor pipelineNodeGraphVisitor = new PipelineNodeGraphVisitor(run);
List<FlowNodeWrapper> wrappers = pipelineNodeGraphVisitor.getPipelineNodes();
assertEquals(7, wrappers.size());
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineRunImplTest method testMultipleRepoChangeSet.
@Test
@Issue("JENKINS-53019")
public void testMultipleRepoChangeSet() throws Exception {
String jenkinsFile = IOUtils.toString(getClass().getResource("mulitpleScms.jenkinsfile"), StandardCharsets.UTF_8).replaceAll("%REPO1%", sampleRepo1.toString()).replaceAll("%REPO2%", sampleRepo2.toString());
WorkflowJob p = j.createProject(WorkflowJob.class, "project");
p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
p.save();
sampleRepo1.init();
sampleRepo2.init();
j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0));
updateREADME(sampleRepo1);
updateREADME(sampleRepo2);
TimeUnit.SECONDS.sleep(1);
updateREADME(sampleRepo2);
TimeUnit.SECONDS.sleep(1);
Run r = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0));
Map<String, Object> runDetails = get("/organizations/jenkins/pipelines/" + p.getName() + "/runs/" + r.getId() + "/");
HashSet<String> commitIds = new HashSet<>();
for (Object o : (ArrayList) runDetails.get("changeSet")) {
commitIds.add(((Map) o).get("checkoutCount").toString());
}
assertEquals(3, ((ArrayList) runDetails.get("changeSet")).size());
assertEquals(new HashSet<>(Arrays.asList("0", "1")), commitIds);
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class PipelineApiTest method getPipelineRunStopTest.
@Test
public void getPipelineRunStopTest() throws Exception {
WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
job1.setDefinition(new CpsFlowDefinition("" + "node {" + " stage ('Build'); " + " semaphore 's' " + " stage ('Test'); " + " echo ('Testing'); " + "}", false));
WorkflowRun b1 = job1.scheduleBuild2(0).waitForStart();
SemaphoreStep.waitForStart("s/1", b1);
Map r = null;
for (int i = 0; i < 10; i++) {
r = request().put("/organizations/jenkins/pipelines/pipeline1/runs/1/stop").build(Map.class);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b1);
FreeStyleProject p = j.createFreeStyleProject("pipeline5");
p.getBuildersList().add(new Shell("echo hello!\nsleep 69"));
FreeStyleBuild b2 = p.scheduleBuild2(0).waitForStart();
for (int i = 0; i < 10; i++) {
r = put("/organizations/jenkins/pipelines/pipeline5/runs/1/stop", null);
if (((String) r.get("state")).equals("FINISHED"))
break;
Thread.sleep(1000);
}
Assert.assertEquals(r.get("state"), "FINISHED");
Assert.assertEquals(r.get("result"), "ABORTED");
j.assertBuildStatus(Result.ABORTED, b2);
}
use of org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition 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.cps.CpsFlowDefinition in project blueocean-plugin by jenkinsci.
the class HTMLArtifactTest method resolveArtifact.
@Test
public void resolveArtifact() throws Exception {
WorkflowJob p = j.createProject(WorkflowJob.class, "project");
URL resource = getClass().getResource("HTMLArtifactTest.jenkinsfile");
String jenkinsFile = IOUtils.toString(resource, StandardCharsets.UTF_8);
p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
p.save();
Run r = p.scheduleBuild2(0).waitForStart();
j.waitForCompletion(r);
BluePipeline bluePipeline = (BluePipeline) BluePipelineFactory.resolve(p);
BlueArtifactContainer artifacts = bluePipeline.getLatestRun().getArtifacts();
Assert.assertEquals(1, StreamSupport.stream(artifacts.spliterator(), false).count());
BlueArtifact artifact = artifacts.iterator().next();
Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/project/runs/1/artifacts/io.jenkins.blueocean.htmlpublisher.HTMLArtifact%253AMy%252520Cool%252520report/", artifact.getLink().getHref());
Assert.assertEquals("My Cool report", artifact.getName());
Assert.assertEquals("My Cool report", artifact.getPath());
Assert.assertNotNull(artifact.getUrl());
Assert.assertEquals(-1, artifact.getSize());
Assert.assertFalse(artifact.isDownloadable());
}
Aggregations