Search in sources :

Example 1 with SCMSourceTrait

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

the class GithubPipelineCreateRequestTest method createPipeline.

@Test
public void createPipeline() throws UnirestException {
    PowerMockito.mockStatic(GitHubWebHook.class);
    GitHubWebHook gitHubWebHookMock = Mockito.spy(GitHubWebHook.class);
    PowerMockito.when(GitHubWebHook.get()).thenReturn(gitHubWebHookMock);
    PowerMockito.when(GitHubWebHook.getJenkinsInstance()).thenReturn(this.j.jenkins);
    String credentialId = createGithubCredential(user);
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(this.crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GithubScm.ID, "uri", githubApiUrl, "credentialId", credentialId, "config", MapsHelper.of("repoOwner", "cloudbeers", "repository", "PR-demo")))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    GitHubSCMSource source = (GitHubSCMSource) mbp.getSCMSources().get(0);
    List<SCMSourceTrait> traits = source.getTraits();
    Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
    BranchDiscoveryTrait branchDiscoveryTrait = SCMTrait.find(traits, BranchDiscoveryTrait.class);
    Assert.assertNotNull(branchDiscoveryTrait);
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranch());
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranchesWithPR());
    ForkPullRequestDiscoveryTrait forkPullRequestDiscoveryTrait = SCMTrait.find(traits, ForkPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(forkPullRequestDiscoveryTrait);
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getTrust() instanceof ForkPullRequestDiscoveryTrait.TrustPermission);
    Assert.assertEquals(1, forkPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
    OriginPullRequestDiscoveryTrait originPullRequestDiscoveryTrait = SCMTrait.find(traits, OriginPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(originPullRequestDiscoveryTrait);
    Assert.assertEquals(1, originPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(originPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
    Mockito.verify(gitHubWebHookMock, Mockito.times(1)).registerHookFor(mbp);
}
Also used : GitHubWebHook(com.cloudbees.jenkins.GitHubWebHook) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) MultiBranchProject(jenkins.branch.MultiBranchProject) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 2 with SCMSourceTrait

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

the class GitPipelineCreateRequest method createSource.

@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
    GitSCMSource gitSource = new GitSCMSource(StringUtils.defaultString(scmConfig.getUri()));
    gitSource.setCredentialsId(computeCredentialId(scmConfig));
    List<SCMSourceTrait> traits = gitSource.getTraits();
    traits.add(new BranchDiscoveryTrait());
    traits.add(new CleanBeforeCheckoutTrait());
    traits.add(new CleanAfterCheckoutTrait());
    traits.add(new LocalBranchTrait());
    return gitSource;
}
Also used : CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) GitSCMSource(jenkins.plugins.git.GitSCMSource) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(jenkins.plugins.git.traits.BranchDiscoveryTrait)

Example 3 with SCMSourceTrait

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

the class GitPipelineCreateRequestTest method createPipeline.

@Test
public void createPipeline() throws UnirestException, IOException {
    User user = login("vivek", "Vivek Pandey", "vivek.pandey@gmail.com");
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_git_pipeline.GitPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GitScm.ID, "uri", sampleRepo.toString()))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    GitSCMSource source = (GitSCMSource) mbp.getSCMSources().get(0);
    List<SCMSourceTrait> traits = source.getTraits();
    Assert.assertNotNull(SCMTrait.find(traits, BranchDiscoveryTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
}
Also used : User(hudson.model.User) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) GitSCMSource(jenkins.plugins.git.GitSCMSource) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(jenkins.plugins.git.traits.BranchDiscoveryTrait) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 4 with SCMSourceTrait

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

the class BitbucketPipelineCreateRequestTest method createdWithTraits.

@Test
public void createdWithTraits() throws Exception {
    String credentialId = createCredential(BitbucketServerScm.ID);
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketPipelineCreateRequest", "scmConfig", MapsHelper.of("id", BitbucketServerScm.ID, "credentialId", credentialId, "uri", apiUrl, "config", MapsHelper.of("repoOwner", "TESTP", "repository", "pipeline-demo-test")))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    BitbucketSCMSource source = (BitbucketSCMSource) mbp.getSCMSources().get(0);
    List<SCMSourceTrait> traits = source.getTraits();
    Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
    BranchDiscoveryTrait branchDiscoveryTrait = SCMTrait.find(traits, BranchDiscoveryTrait.class);
    Assert.assertNotNull(branchDiscoveryTrait);
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranch());
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranchesWithPR());
    ForkPullRequestDiscoveryTrait forkPullRequestDiscoveryTrait = SCMTrait.find(traits, ForkPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(forkPullRequestDiscoveryTrait);
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getTrust() instanceof ForkPullRequestDiscoveryTrait.TrustTeamForks);
    Assert.assertEquals(1, forkPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
    OriginPullRequestDiscoveryTrait originPullRequestDiscoveryTrait = SCMTrait.find(traits, OriginPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(originPullRequestDiscoveryTrait);
    Assert.assertEquals(1, originPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(originPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
}
Also used : OriginPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) ForkPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

CleanAfterCheckoutTrait (jenkins.plugins.git.traits.CleanAfterCheckoutTrait)4 CleanBeforeCheckoutTrait (jenkins.plugins.git.traits.CleanBeforeCheckoutTrait)4 LocalBranchTrait (jenkins.plugins.git.traits.LocalBranchTrait)4 SCMSourceTrait (jenkins.scm.api.trait.SCMSourceTrait)4 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)3 Map (java.util.Map)3 MultiBranchProject (jenkins.branch.MultiBranchProject)3 Test (org.junit.Test)3 GitSCMSource (jenkins.plugins.git.GitSCMSource)2 BranchDiscoveryTrait (jenkins.plugins.git.traits.BranchDiscoveryTrait)2 GitHubWebHook (com.cloudbees.jenkins.GitHubWebHook)1 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)1 BranchDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait)1 ForkPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait)1 OriginPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait)1 User (hudson.model.User)1 BranchDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait)1 ForkPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait)1 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)1 OriginPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait)1