Search in sources :

Example 36 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();
    // check MBP capabilities
    Map<String, Object> response = get("/organizations/jenkins/pipelines/p/");
    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(BLUE_SCM) && classes.contains(JENKINS_MULTI_BRANCH_PROJECT) && classes.contains(BLUE_MULTI_BRANCH_PIPELINE) && classes.contains(BLUE_PIPELINE_FOLDER) && classes.contains(JENKINS_ABSTRACT_FOLDER) && classes.contains(BLUE_PIPELINE));
    response = get("/organizations/jenkins/pipelines/p/branches/master/", Map.class);
    clazz = (String) response.get("_class");
    response = get("/classes/" + clazz + "/");
    Assert.assertNotNull(response);
    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) 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) Test(org.junit.Test)

Example 37 with SCMSource

use of jenkins.scm.api.SCMSource 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) DefaultBranchPropertyStrategy(jenkins.branch.DefaultBranchPropertyStrategy) Map(java.util.Map) Test(org.junit.Test)

Example 38 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) Test(org.junit.Test)

Example 39 with SCMSource

use of jenkins.scm.api.SCMSource 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 = urlMapper.getUrl(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 = urlMapper.getUrl(masterJob);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob featureUx1Job = findBranchProject(mp, "feature/ux-1");
    blueOceanURL = urlMapper.getUrl(featureUx1Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    WorkflowJob feature2Job = findBranchProject(mp, "feature2");
    blueOceanURL = urlMapper.getUrl(feature2Job);
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/branches/", blueOceanURL);
    // Runs on the jobs
    blueOceanURL = urlMapper.getUrl(masterJob.getFirstBuild());
    assertURL("blue/organizations/jenkins/folder1%2Ffolder%20two%20with%20spaces%2Fp/detail/master/1/", blueOceanURL);
    blueOceanURL = urlMapper.getUrl(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)

Example 40 with SCMSource

use of jenkins.scm.api.SCMSource in project gitlab-branch-source-plugin by Argelbargel.

the class GitLabSCMItemListener method updateProperties.

private boolean updateProperties(Job<?, ?> job, SCMSourceOwner sourceOwner, String sourceId) {
    SCMSource source = sourceOwner.getSCMSource(sourceId);
    if (source instanceof GitLabSCMSource) {
        String connectionName = ((GitLabSCMSource) source).getSourceSettings().getConnectionName();
        GitLabConnectionProperty property = job.getProperty(GitLabConnectionProperty.class);
        if (property == null || !connectionName.equals(property.getGitLabConnection())) {
            updateProperties(job, connectionName);
            return true;
        }
    }
    return false;
}
Also used : GitLabConnectionProperty(com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty) SCMSource(jenkins.scm.api.SCMSource)

Aggregations

SCMSource (jenkins.scm.api.SCMSource)40 GitSCMSource (jenkins.plugins.git.GitSCMSource)36 BranchSource (jenkins.branch.BranchSource)35 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)35 Test (org.junit.Test)32 DefaultBranchPropertyStrategy (jenkins.branch.DefaultBranchPropertyStrategy)29 Map (java.util.Map)26 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)24 List (java.util.List)14 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)12 ArrayList (java.util.ArrayList)11 Queue (hudson.model.Queue)5 User (hudson.model.User)5 MockFolder (org.jvnet.hudson.test.MockFolder)5 ExtensionList (hudson.ExtensionList)3 FreeStyleProject (hudson.model.FreeStyleProject)3 RunList (hudson.util.RunList)3 MultiBranchProject (jenkins.branch.MultiBranchProject)3 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)3 Ignore (org.junit.Ignore)3