Search in sources :

Example 16 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelineRuns.

@Test
public void getMultiBranchPipelineRuns() 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, "master");
    j.waitUntilNoActivity();
    WorkflowRun b1 = p.getLastBuild();
    assertEquals(1, b1.getNumber());
    assertEquals(3, mp.getItems().size());
    //execute feature/ux-1 branch build
    p = scheduleAndFindBranchProject(mp, "feature%2Fux-1");
    j.waitUntilNoActivity();
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(1, b2.getNumber());
    //execute feature 2 branch build
    p = scheduleAndFindBranchProject(mp, "feature2");
    j.waitUntilNoActivity();
    WorkflowRun b3 = p.getLastBuild();
    assertEquals(1, b3.getNumber());
    List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
    List<String> branchNames = new ArrayList<>();
    List<Integer> weather = new ArrayList<>();
    for (Map b : br) {
        branchNames.add((String) b.get("name"));
        weather.add((int) b.get("weatherScore"));
    }
    Assert.assertTrue(branchNames.contains(((Map) (br.get(0).get("latestRun"))).get("pipeline")));
    for (String n : branches) {
        assertTrue(branchNames.contains(n));
    }
    WorkflowRun[] runs = { b1, b2, b3 };
    int i = 0;
    for (String n : branches) {
        WorkflowRun b = runs[i];
        j.waitForCompletion(b);
        Map run = get("/organizations/jenkins/pipelines/p/branches/" + Util.rawEncode(n) + "/runs/" + b.getId());
        validateRun(b, run);
        i++;
    }
    Map pr = get("/organizations/jenkins/pipelines/p/");
    validateMultiBranchPipeline(mp, pr, 3, 3, 0);
    sampleRepo.git("checkout", "master");
    sampleRepo.write("file", "subsequent content11");
    sampleRepo.git("commit", "--all", "--message=tweaked11");
    p = scheduleAndFindBranchProject(mp, "master");
    j.waitUntilNoActivity();
    WorkflowRun b4 = p.getLastBuild();
    assertEquals(2, b4.getNumber());
    List<Map> run = get("/organizations/jenkins/pipelines/p/branches/master/runs/", List.class);
    validateRun(b4, run.get(0));
}
Also used : ArrayList(java.util.ArrayList) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) 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) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 17 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipeline.

@Test
public void getMultiBranchPipeline() throws IOException, ExecutionException, InterruptedException {
    Assume.assumeTrue(runAllTests());
    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();
    Map resp = get("/organizations/jenkins/pipelines/p/");
    validateMultiBranchPipeline(mp, resp, 3);
    List<String> names = (List<String>) resp.get("branchNames");
    IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(names, branches);
    List<Map> br = get("/organizations/jenkins/pipelines/p/branches", List.class);
    List<String> branchNames = new ArrayList<>();
    List<Integer> weather = new ArrayList<>();
    for (Map b : br) {
        branchNames.add((String) b.get("name"));
        weather.add((int) b.get("weatherScore"));
    }
    for (String n : branches) {
        assertTrue(branchNames.contains(n));
    }
    for (int s : weather) {
        assertEquals(100, s);
    }
}
Also used : ArrayList(java.util.ArrayList) GitSCMSource(jenkins.plugins.git.GitSCMSource) SCMSource(jenkins.scm.api.SCMSource) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 18 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy 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/queue/" + 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 19 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getPipelineJobActivitiesNoBranches.

@Test
public void getPipelineJobActivitiesNoBranches() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    List l = request().get("/organizations/jenkins/pipelines/p/activities").build(List.class);
    Assert.assertEquals(0, l.size());
    List branches = request().get("/organizations/jenkins/pipelines/p/branches").build(List.class);
    Assert.assertEquals(0, branches.size());
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) GitSCMSource(jenkins.plugins.git.GitSCMSource) BranchSource(jenkins.branch.BranchSource) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Test(org.junit.Test)

Example 20 with DefaultBranchPropertyStrategy

use of jenkins.branch.DefaultBranchPropertyStrategy in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method branchCapabilityTest.

@Test
public void branchCapabilityTest() 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, "master");
    j.waitUntilNoActivity();
    Map response = get("/organizations/jenkins/pipelines/p/branches/master/", Map.class);
    String clazz = (String) response.get("_class");
    response = get("/classes/" + clazz + "/");
    Assert.assertNotNull(response);
    List<String> classes = (List<String>) response.get("classes");
    Assert.assertTrue(classes.contains(JENKINS_JOB) && classes.contains(JENKINS_WORKFLOW_JOB) && classes.contains(BLUE_BRANCH) && classes.contains(BLUE_PIPELINE) && classes.contains(PULL_REQUEST));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) 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)

Aggregations

BranchSource (jenkins.branch.BranchSource)23 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)23 GitSCMSource (jenkins.plugins.git.GitSCMSource)23 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)23 SCMSource (jenkins.scm.api.SCMSource)22 Test (org.junit.Test)21 Map (java.util.Map)19 ImmutableMap (com.google.common.collect.ImmutableMap)18 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)14 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)8 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)4 MockFolder (org.jvnet.hudson.test.MockFolder)4 FreeStyleProject (hudson.model.FreeStyleProject)3 Queue (hudson.model.Queue)2 BuildData (hudson.plugins.git.util.BuildData)1 HudsonPrivateSecurityRealm (hudson.security.HudsonPrivateSecurityRealm)1 LegacyAuthorizationStrategy (hudson.security.LegacyAuthorizationStrategy)1 SimpleDateFormat (java.text.SimpleDateFormat)1