Search in sources :

Example 21 with SCMSource

use of jenkins.scm.api.SCMSource 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 22 with SCMSource

use of jenkins.scm.api.SCMSource 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)

Example 23 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getPipelineJobActivities.

//Disabled test for now as I can't get it to work. Tested manually.
//@Test
public void getPipelineJobActivities() throws Exception {
    WorkflowMultiBranchProject mp = j.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
    sampleRepo1.init();
    sampleRepo1.write("Jenkinsfile", "stage 'build'\n " + "node {echo 'Building'}\n" + "stage 'test'\nnode { echo 'Testing'}\n" + "sleep 10000 \n" + "stage 'deploy'\nnode { echo 'Deploying'}\n");
    sampleRepo1.write("file", "initial content");
    sampleRepo1.git("add", "Jenkinsfile");
    sampleRepo1.git("commit", "--all", "--message=flow");
    //create feature branch
    sampleRepo1.git("checkout", "-b", "abc");
    sampleRepo1.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; " + "node {" + "   stage ('Build'); " + "   echo ('Building'); " + "   stage ('Test'); sleep 10000; " + "   echo ('Testing'); " + "   stage ('Deploy'); " + "   echo ('Deploying'); " + "}");
    ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
    sampleRepo1.write("file", "subsequent content1");
    sampleRepo1.git("commit", "--all", "--message=tweaked1");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo1.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    for (SCMSource source : mp.getSCMSources()) {
        assertEquals(mp, source.getOwner());
    }
    scheduleAndFindBranchProject(mp);
    for (WorkflowJob job : mp.getItems()) {
        Queue.Item item = job.getQueueItem();
        if (item != null) {
            item.getFuture().waitForStart();
        }
        job.setConcurrentBuild(false);
        job.scheduleBuild2(0);
        job.scheduleBuild2(0);
    }
    List l = request().get("/organizations/jenkins/pipelines/p/activities").build(List.class);
    Assert.assertEquals(4, l.size());
    Assert.assertEquals("io.jenkins.blueocean.service.embedded.rest.QueueItemImpl", ((Map) l.get(0)).get("_class"));
    Assert.assertEquals("io.jenkins.blueocean.rest.impl.pipeline.PipelineRunImpl", ((Map) l.get(2)).get("_class"));
}
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) Queue(hudson.model.Queue)

Example 24 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method getMultiBranchPipelineInsideFolder.

@Test
public void getMultiBranchPipelineInsideFolder() throws IOException, ExecutionException, InterruptedException {
    MockFolder folder1 = j.createFolder("folder1");
    WorkflowMultiBranchProject mp = folder1.createProject(WorkflowMultiBranchProject.class, "p");
    mp.setDisplayName("My MBP");
    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/");
    validateMultiBranchPipeline(mp, r, 3);
    Assert.assertEquals("/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/p/", ((Map) ((Map) r.get("_links")).get("self")).get("href"));
    Assert.assertEquals("folder1/My%20MBP", r.get("fullDisplayName"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/master/");
    Assert.assertEquals("folder1/My%20MBP/master", r.get("fullDisplayName"));
}
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 25 with SCMSource

use of jenkins.scm.api.SCMSource in project blueocean-plugin by jenkinsci.

the class MultiBranchTest method testMultiBranchPipelineBranchSecurePermissions.

@Test
public void testMultiBranchPipelineBranchSecurePermissions() throws IOException, ExecutionException, InterruptedException {
    j.jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false));
    j.jenkins.setAuthorizationStrategy(new LegacyAuthorizationStrategy());
    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.assertFalse(permissions.get("create"));
    Assert.assertTrue(permissions.get("read"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    r = get("/organizations/jenkins/pipelines/folder1/pipelines/p/branches/master/");
    permissions = (Map<String, Boolean>) r.get("permissions");
    Assert.assertFalse(permissions.get("create"));
    Assert.assertFalse(permissions.get("start"));
    Assert.assertFalse(permissions.get("stop"));
    Assert.assertTrue(permissions.get("read"));
}
Also used : WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) LegacyAuthorizationStrategy(hudson.security.LegacyAuthorizationStrategy) 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) HudsonPrivateSecurityRealm(hudson.security.HudsonPrivateSecurityRealm) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

SCMSource (jenkins.scm.api.SCMSource)26 BranchSource (jenkins.branch.BranchSource)25 GitSCMSource (jenkins.plugins.git.GitSCMSource)25 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)25 Test (org.junit.Test)23 Map (java.util.Map)22 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)22 ImmutableMap (com.google.common.collect.ImmutableMap)21 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)17 List (java.util.List)11 ImmutableList (com.google.common.collect.ImmutableList)10 ArrayList (java.util.ArrayList)9 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 GitLabConnectionProperty (com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty)1 BuildData (hudson.plugins.git.util.BuildData)1