Search in sources :

Example 6 with WorkflowMultiBranchProject

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

the class MultiBranchTest method testMultiBranchPipelineBranchUnsecurePermissions.

@Test
public void testMultiBranchPipelineBranchUnsecurePermissions() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.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 r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/");
    Map<String, Boolean> permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertTrue(permissions.get("create"));
    Assert.assertTrue(permissions.get("start"));
    Assert.assertTrue(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
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) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 7 with WorkflowMultiBranchProject

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

the class MultiBranchTest method getMultiBranchPipelineRunChangeSets.

@Test
public void getMultiBranchPipelineRunChangeSets() throws Exception {
    setupScmWithChangeSet();
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo3.toString(), "", "*", "", false)));
    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(1, mp.getItems().size());
    String[] messages = { "tweaked11", "tweaked12", "tweaked13", "tweaked14" };
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content11");
    sampleRepo3.git("commit", "--all", "--message=" + messages[0]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content12");
    sampleRepo3.git("commit", "--all", "--message=" + messages[1]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content13");
    sampleRepo3.git("commit", "--all", "--message=" + messages[2]);
    sampleRepo3.git("checkout", "master");
    sampleRepo3.write("file", "subsequent content14");
    sampleRepo3.git("commit", "--all", "--message=" + messages[3]);
    WorkflowRun b4 = p.scheduleBuild2(0).get();
    j.waitUntilNoActivity();
    assertEquals(b4.getNumber(), 2);
    Assert.assertEquals(1, b4.getChangeSets().size());
    ChangeLogSet.Entry changeLog = b4.getChangeSets().get(0).iterator().next();
    int i = 0;
    for (ChangeLogSet.Entry c : b4.getChangeSets().get(0)) {
        Assert.assertEquals(messages[i], c.getMsg());
        i++;
    }
    Map run = get("/organizations/jenkins/pipelines/p/branches/master/runs/" + b4.getId() + "/");
    validateRun(b4, run);
    List<Map> changetSet = (List<Map>) run.get("changeSet");
    Map c = changetSet.get(0);
    Assert.assertEquals(changeLog.getCommitId(), c.get("commitId"));
    Map a = (Map) c.get("author");
    Assert.assertEquals(changeLog.getAuthor().getId(), a.get("id"));
    Assert.assertEquals(changeLog.getAuthor().getFullName(), a.get("fullName"));
    int j = 0;
    for (ChangeLogSet.Entry cs : b4.getChangeSets().get(0)) {
        Assert.assertEquals(cs.getCommitId(), changetSet.get(j).get("commitId"));
        j++;
    }
    Assert.assertEquals(i, j);
}
Also used : ChangeLogSet(hudson.scm.ChangeLogSet) 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) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 8 with WorkflowMultiBranchProject

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

the class MultiBranchTest method resolveMbpLink.

@Test
public void resolveMbpLink() throws Exception {
    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();
    j.waitUntilNoActivity();
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/", LinkResolver.resolveLink(mp).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/master/", LinkResolver.resolveLink(mp.getBranch("master")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature%252Fux-1/", LinkResolver.resolveLink(mp.getBranch("feature%2Fux-1")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/p/branches/feature2/", LinkResolver.resolveLink(mp.getBranch("feature2")).getHref());
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/f/", LinkResolver.resolveLink(f).getHref());
}
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) Test(org.junit.Test)

Example 9 with WorkflowMultiBranchProject

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

the class MultiBranchTest method getPipelinesTest.

@Test
public void getPipelinesTest() 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();
    List<Map> responses = get("/search/?q=type:pipeline;excludedFromFlattening:jenkins.branch.MultiBranchProject", List.class);
    Assert.assertEquals(1, responses.size());
}
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 10 with WorkflowMultiBranchProject

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

the class MultiBranchTest method getMultiBranchPipelines.

@Test
public void getMultiBranchPipelines() 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/", List.class);
    Assert.assertEquals(2, resp.size());
    validatePipeline(f, resp.get(0));
    validateMultiBranchPipeline(mp, resp.get(1), 3);
    Assert.assertEquals(mp.getBranch("master").getBuildHealth().getScore(), resp.get(0).get("weatherScore"));
}
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)

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