Search in sources :

Example 41 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method startMultiBranchPipelineRuns.

@Test
public void startMultiBranchPipelineRuns() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    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());
    }
    WorkflowJob p = scheduleAndFindBranchProject(mp, "feature%2Fux-1");
    j.waitUntilNoActivity();
    Map resp = post("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode("feature%2Fux-1") + "/runs/", Collections.EMPTY_MAP);
    String id = (String) resp.get("id");
    String link = getHrefFromLinks(resp, "self");
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/runs/" + id + "/", link);
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 42 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class PipelineNodeTest method declarativeSyntheticSkippedStage.

@Test
public void declarativeSyntheticSkippedStage() throws Exception {
    setupScm("pipeline {\n" + "    agent any\n" + "    stages {\n" + "        stage(\"build\") {\n" + "            steps{\n" + "              sh 'echo \"Start Build\"'\n" + "              echo 'End Build'\n" + "            }\n" + "        }\n" + "        stage(\"SkippedStage\") {\n" + "            when {\n" + "        expression {\n" + "                return false\n" + "        }\n" + "            }\n" + "            steps {\n" + "                script {\n" + "                    echo \"World\"\n" + "                    echo \"Heal it\"\n" + "                }\n" + "\n" + "            }\n" + "        }\n" + "        stage(\"deploy\") {\n" + "            steps{\n" + "              sh 'echo \"Start Deploy\"'\n" + "              sh 'echo \"Deploying...\"'\n" + "              sh 'echo \"End Deploy\"'\n" + "            }           \n" + "        }\n" + "    }\n" + "    post {\n" + "        failure {\n" + "            echo \"failed\"\n" + "        }\n" + "        success {\n" + "            echo \"success\"\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(3, stages.size());
    Assert.assertEquals("build", stages.get(0).getDisplayName());
    Assert.assertEquals("SkippedStage", stages.get(1).getDisplayName());
    Assert.assertEquals("deploy", stages.get(2).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(3, resp.size());
    Assert.assertEquals("build", resp.get(0).get("displayName"));
    Assert.assertEquals("SkippedStage", resp.get(1).get("displayName"));
    Assert.assertEquals("deploy", resp.get(2).get("displayName"));
    // check status
    Assert.assertEquals("SUCCESS", resp.get(0).get("result"));
    Assert.assertEquals("FINISHED", resp.get(0).get("state"));
    Assert.assertEquals("NOT_BUILT", resp.get(1).get("result"));
    Assert.assertEquals("SKIPPED", resp.get(1).get("state"));
    Assert.assertEquals("SUCCESS", resp.get(2).get("result"));
    Assert.assertEquals("FINISHED", resp.get(2).get("state"));
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/steps/", List.class);
    Assert.assertEquals(7, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(0).getId() + "/steps/", List.class);
    Assert.assertEquals(3, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(1).getId() + "/steps/", List.class);
    Assert.assertEquals(0, resp.size());
    resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/" + stages.get(2).getId() + "/steps/", List.class);
    Assert.assertEquals(4, resp.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) RunList(hudson.util.RunList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) Test(org.junit.Test)

Example 43 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class PipelineScmTest method authorizedUserContentUpdateShouldSucceed.

@Test
public void authorizedUserContentUpdateShouldSucceed() throws IOException, ExecutionException, InterruptedException, UnirestException {
    WorkflowMultiBranchProject mp = j.createProject(WorkflowMultiBranchProject.class, "mbp");
    mp.setDisplayName("My MBP");
    Map content = new RequestBuilder(baseUrl).status(200).jwtToken(getJwtToken(j.jenkins, bob.getId(), bob.getId())).data(ImmutableMap.of("content", ImmutableMap.of("data", "Hello World Again!"))).put("/organizations/jenkins/pipelines/mbp/scm/content").build(Map.class);
    assertNotNull(content);
    assertEquals("Hello World Again!", ((Map) content.get("content")).get("data"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 44 with WorkflowMultiBranchProject

use of org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject in project blueocean-plugin by jenkinsci.

the class PipelineScmTest method AuthorizedUserContentAccessShouldSucceed.

@Test
public void AuthorizedUserContentAccessShouldSucceed() throws IOException, ExecutionException, InterruptedException, UnirestException {
    WorkflowMultiBranchProject mp = j.createProject(WorkflowMultiBranchProject.class, "mbp");
    mp.setDisplayName("My MBP");
    Map content = new RequestBuilder(baseUrl).status(200).jwtToken(getJwtToken(j.jenkins, bob.getId(), bob.getId())).get("/organizations/jenkins/pipelines/mbp/scm/content").build(Map.class);
    assertNotNull(content);
    assertEquals("Hello World!", ((Map) content.get("content")).get("data"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)44 Test (org.junit.Test)38 BranchSource (jenkins.branch.BranchSource)36 GitSCMSource (jenkins.plugins.git.GitSCMSource)36 SCMSource (jenkins.scm.api.SCMSource)32 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)31 Map (java.util.Map)28 ImmutableMap (com.google.common.collect.ImmutableMap)26 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)26 List (java.util.List)16 ImmutableList (com.google.common.collect.ImmutableList)15 ArrayList (java.util.ArrayList)13 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)12 User (hudson.model.User)7 Queue (hudson.model.Queue)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 FreeStyleProject (hudson.model.FreeStyleProject)3 Item (hudson.model.Item)3 RunList (hudson.util.RunList)3 Domain (com.cloudbees.plugins.credentials.domains.Domain)2