Search in sources :

Example 91 with CpsFlowDefinition

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());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 92 with CpsFlowDefinition

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);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) ArrayList(java.util.ArrayList) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) HashSet(java.util.HashSet) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 93 with CpsFlowDefinition

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);
}
Also used : Shell(hudson.tasks.Shell) CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FreeStyleBuild(hudson.model.FreeStyleBuild) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) FreeStyleProject(hudson.model.FreeStyleProject) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 94 with CpsFlowDefinition

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);
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Example 95 with CpsFlowDefinition

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());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) BlueArtifact(io.jenkins.blueocean.rest.model.BlueArtifact) BluePipeline(io.jenkins.blueocean.rest.model.BluePipeline) BlueArtifactContainer(io.jenkins.blueocean.rest.model.BlueArtifactContainer) Run(hudson.model.Run) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)220 Test (org.junit.Test)210 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)182 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)124 Issue (org.jvnet.hudson.test.Issue)63 Map (java.util.Map)60 List (java.util.List)26 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)22 RunList (hudson.util.RunList)20 ExtensionList (hudson.ExtensionList)19 Statement (org.junit.runners.model.Statement)19 Run (hudson.model.Run)17 URL (java.net.URL)16 AmazonCloudFormation (com.amazonaws.services.cloudformation.AmazonCloudFormation)12 TaskListener (hudson.model.TaskListener)11 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)10 NodeStepTypePredicate (org.jenkinsci.plugins.workflow.graphanalysis.NodeStepTypePredicate)9 DescribeChangeSetResult (com.amazonaws.services.cloudformation.model.DescribeChangeSetResult)7 Parameter (com.amazonaws.services.cloudformation.model.Parameter)6