Search in sources :

Example 11 with WorkflowMultiBranchProject

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

the class MultiBranchTest method getBranchWithEncodedPath.

@Test
public void getBranchWithEncodedPath() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    FreeStyleProject f = j.jenkins.createProject(FreeStyleProject.class, "f");
    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();
    List<Map> resp = get("/organizations/jenkins/pipelines/p/branches/", List.class);
    String href = null;
    for (Map r : resp) {
        if (r.get("name").equals("feature%2Fux-1")) {
            href = (String) ((Map) ((Map) r.get("_links")).get("self")).get("href");
            href = StringUtils.substringAfter(href, "/blue/rest");
        }
    }
    Assert.assertNotNull(href);
    Map r = get(href);
    Assert.assertEquals("feature%2Fux-1", r.get("name"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) FreeStyleProject(hudson.model.FreeStyleProject) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 12 with WorkflowMultiBranchProject

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

the class MultiBranchTest method getMultiBranchPipelinesWithNonMasterBranch.

@Test
public void getMultiBranchPipelinesWithNonMasterBranch() throws Exception {
    sampleRepo.git("branch", "-D", "master");
    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());
    }
    mp.scheduleBuild2(0).getFuture().get();
    List<Map> resp = get("/organizations/jenkins/pipelines/", List.class);
    Assert.assertEquals(1, resp.size());
    validateMultiBranchPipeline(mp, resp.get(0), 2);
    assertNull(mp.getBranch("master"));
}
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) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 13 with WorkflowMultiBranchProject

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

the class PipelineNodeTest method declarativeSyntheticSteps.

@Test
public void declarativeSyntheticSteps() 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(\"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(2, stages.size());
    Assert.assertEquals("build", stages.get(0).getDisplayName());
    Assert.assertEquals("deploy", stages.get(1).getDisplayName());
    List<Map> resp = get("/organizations/jenkins/pipelines/p/pipelines/master/runs/" + b1.getId() + "/nodes/", List.class);
    Assert.assertEquals(2, resp.size());
    Assert.assertEquals("build", resp.get(0).get("displayName"));
    Assert.assertEquals("deploy", resp.get(1).get("displayName"));
    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(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 14 with WorkflowMultiBranchProject

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

the class BlueMessageEnricher method enrich.

@Override
public void enrich(@Nonnull Message message) {
    // TODO: Get organization name in generic way once multi-organization support is implemented in API
    message.set(EventProps.Jenkins.jenkins_org, OrganizationImpl.INSTANCE.getName());
    String channelName = message.getChannelName();
    if (channelName.equals(Events.JobChannel.NAME)) {
        JobChannelMessage jobChannelMessage = (JobChannelMessage) message;
        Item jobChannelItem = jobChannelMessage.getJobChannelItem();
        Link jobUrl = LinkResolver.resolveLink(jobChannelItem);
        jobChannelMessage.set(BlueEventProps.blueocean_job_rest_url, jobUrl.getHref());
        jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, jobChannelItem.getFullName());
        if (jobChannelItem instanceof WorkflowJob) {
            ItemGroup<? extends Item> parent = jobChannelItem.getParent();
            if (parent instanceof WorkflowMultiBranchProject) {
                String multiBranchProjectName = parent.getFullName();
                jobChannelMessage.set(BlueEventProps.blueocean_job_pipeline_name, multiBranchProjectName);
                jobChannelMessage.set(BlueEventProps.blueocean_job_branch_name, jobChannelItem.getName());
            }
        }
    }
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) Item(hudson.model.Item) JobChannelMessage(org.jenkinsci.plugins.pubsub.JobChannelMessage) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Link(io.jenkins.blueocean.rest.hal.Link)

Example 15 with WorkflowMultiBranchProject

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

the class BlueOceanWebURLBuilderTest method getMultiBranchPipelineInsideFolder.

@Test
public void getMultiBranchPipelineInsideFolder() throws Exception {
    MockFolder folder1 = jenkinsRule.createFolder("folder1");
    MockFolder folder2 = folder1.createProject(MockFolder.class, "folder two with spaces");
    WorkflowMultiBranchProject mp = folder2.createProject(WorkflowMultiBranchProject.class, "p");
    String blueOceanURL;
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(mp);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    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();
    jenkinsRule.waitUntilNoActivity();
    // All branch jobs should just resolve back to the same top level branches
    // page for the multibranch job in Blue Ocean.
    WorkflowJob masterJob = findBranchProject(mp, "master");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(masterJob);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(featureUx1Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    WorkflowJob feature2Job = findBranchProject(mp, "feature2");
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(feature2Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches", blueOceanURL);
    // Runs on the jobs
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(masterJob.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1", blueOceanURL);
    blueOceanURL = BlueOceanWebURLBuilder.toBlueOceanURL(featureUx1Job.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/feature%2Fux-1/1", blueOceanURL);
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) 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) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Test(org.junit.Test)

Aggregations

WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)28 BranchSource (jenkins.branch.BranchSource)27 GitSCMSource (jenkins.plugins.git.GitSCMSource)27 SCMSource (jenkins.scm.api.SCMSource)25 Test (org.junit.Test)24 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)23 Map (java.util.Map)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)18 List (java.util.List)12 ImmutableList (com.google.common.collect.ImmutableList)11 ArrayList (java.util.ArrayList)10 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)7 MockFolder (org.jvnet.hudson.test.MockFolder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 Queue (hudson.model.Queue)2 RunList (hudson.util.RunList)2 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)2 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 Cause (hudson.model.Cause)1