Search in sources :

Example 36 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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 37 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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().toString());
    URL resource = Resources.getResource(contextClass, jenkinsFileName);
    String jenkinsFile = Resources.toString(resource, Charsets.UTF_8);
    p.setDefinition(new CpsFlowDefinition(jenkinsFile, true));
    p.save();
    return p;
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) URL(java.net.URL)

Example 38 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob 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(Lists.newArrayList("2", "3", "4", "5", "6", "8"), new PipelineEventListener().getBranch(parallels.get(0)));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 39 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class SseEventTest method multiBranchJobEventsWithCustomOrg.

@Test
public void multiBranchJobEventsWithCustomOrg() throws Exception {
    MockFolder folder = j.createFolder("TestOrgFolderName");
    assertNotNull(folder);
    setupScm();
    final OneShotEvent success = new OneShotEvent();
    final Boolean[] pipelineNameMatched = { null };
    final Boolean[] mbpPipelineNameMatched = { null };
    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {

        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            if ("job".equals(message.get(jenkins_channel))) {
                if ("org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject".equals(message.get(jenkins_object_type))) {
                    if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        mbpPipelineNameMatched[0] = true;
                    } else {
                        mbpPipelineNameMatched[0] = false;
                    }
                } else if ("org.jenkinsci.plugins.workflow.job.WorkflowJob".equals(message.get(jenkins_object_type))) {
                    if ("pipeline1".equals(message.get(blueocean_job_pipeline_name))) {
                        pipelineNameMatched[0] = true;
                    } else {
                        pipelineNameMatched[0] = false;
                    }
                }
            }
            if (pipelineNameMatched[0] != null && mbpPipelineNameMatched[0] != null) {
                success.signal();
            }
        }
    });
    con.subscribe("pipeline");
    con.subscribe("job");
    final WorkflowMultiBranchProject mp = folder.createProject(WorkflowMultiBranchProject.class, "pipeline1");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    mp.scheduleBuild2(0).getFuture().get();
    WorkflowJob p = mp.getItem("master");
    if (p == null) {
        mp.getIndexing().writeWholeLogTo(System.out);
        fail("master project not found");
    }
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(2, mp.getItems().size());
    success.block(5000);
    con.close();
    if (success.isSignaled()) {
        assertTrue(pipelineNameMatched[0]);
        assertTrue(mbpPipelineNameMatched[0]);
    }
}
Also used : Message(org.jenkinsci.plugins.pubsub.Message) ChannelSubscriber(org.jenkinsci.plugins.pubsub.ChannelSubscriber) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) MockFolder(org.jvnet.hudson.test.MockFolder) BranchSource(jenkins.branch.BranchSource) SSEConnection(io.jenkins.blueocean.events.sse.SSEConnection) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) OneShotEvent(hudson.util.OneShotEvent) Test(org.junit.Test)

Example 40 with WorkflowJob

use of org.jenkinsci.plugins.workflow.job.WorkflowJob in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method BlockStageStepsWithDesc.

@Test
public void BlockStageStepsWithDesc() throws Exception {
    WorkflowJob job1 = j.jenkins.createProject(WorkflowJob.class, "pipeline1");
    job1.setDefinition(new CpsFlowDefinition("node{\n" + "    stage ('Build') {\n" + "            sh 'echo \"Building\"'\n" + "    }\n" + "    stage ('Test') {\n" + "            sh 'echo testing'\n" + "    }\n" + "    stage ('Deploy') {\n" + "            sh 'echo deploy'\n" + "    }\n" + "}"));
    WorkflowRun b1 = job1.scheduleBuild2(0).get();
    j.assertBuildStatus(Result.SUCCESS, b1);
    List<Map> steps = get("/organizations/jenkins/pipelines/pipeline1/runs/1/steps/", List.class);
    Assert.assertEquals(3, steps.size());
    Assert.assertEquals("Shell Script", steps.get(0).get("displayName"));
    Assert.assertEquals("Shell Script", steps.get(1).get("displayName"));
    Assert.assertEquals("Shell Script", steps.get(2).get("displayName"));
    Assert.assertEquals("echo \"Building\"", steps.get(0).get("displayDescription"));
    Assert.assertEquals("echo testing", steps.get(1).get("displayDescription"));
    Assert.assertEquals("echo deploy", steps.get(2).get("displayDescription"));
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Test(org.junit.Test)

Aggregations

WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)100 Test (org.junit.Test)91 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)74 Map (java.util.Map)73 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)62 ImmutableMap (com.google.common.collect.ImmutableMap)55 List (java.util.List)34 ImmutableList (com.google.common.collect.ImmutableList)28 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)26 BranchSource (jenkins.branch.BranchSource)24 GitSCMSource (jenkins.plugins.git.GitSCMSource)24 SCMSource (jenkins.scm.api.SCMSource)23 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)20 RunList (hudson.util.RunList)19 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)17 ArrayList (java.util.ArrayList)10 URL (java.net.URL)9 Run (hudson.model.Run)8 Issue (org.jvnet.hudson.test.Issue)8 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)7