Search in sources :

Example 1 with BitbucketSCMSource

use of com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource in project blueocean-plugin by jenkinsci.

the class BitbucketPipelineCreateRequest method createSource.

@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
    /* scmConfig.uri presence is already validated in {@link #validate} but lets check just in case */
    if (StringUtils.isBlank(scmConfig.getUri())) {
        throw new ServiceException.BadRequestException("scmConfig.uri must be present");
    }
    Set<ChangeRequestCheckoutStrategy> strategies = new HashSet<>();
    strategies.add(ChangeRequestCheckoutStrategy.MERGE);
    BitbucketSCMSource bitbucketSCMSource = new BitbucketSCMSourceBuilder(null, scmConfig.getUri(), computeCredentialId(scmConfig), (String) scmConfig.getConfig().get("repoOwner"), (String) scmConfig.getConfig().get("repository")).withTrait(// take all branches
    new BranchDiscoveryTrait(true, true)).withTrait(new ForkPullRequestDiscoveryTrait(strategies, new ForkPullRequestDiscoveryTrait.TrustTeamForks())).withTrait(new OriginPullRequestDiscoveryTrait(strategies)).withTrait(new CleanBeforeCheckoutTrait()).withTrait(new CleanAfterCheckoutTrait()).withTrait(new LocalBranchTrait()).build();
    // Setup Jenkins root url, if not set bitbucket cloud notification will fail
    JenkinsLocationConfiguration jenkinsLocationConfiguration = JenkinsLocationConfiguration.get();
    if (jenkinsLocationConfiguration != null) {
        String url = jenkinsLocationConfiguration.getUrl();
        if (url == null) {
            url = Jenkins.getInstance().getRootUrl();
            if (url != null) {
                jenkinsLocationConfiguration.setUrl(url);
            }
        }
    }
    return bitbucketSCMSource;
}
Also used : OriginPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait) JenkinsLocationConfiguration(jenkins.model.JenkinsLocationConfiguration) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) BitbucketSCMSourceBuilder(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceBuilder) ChangeRequestCheckoutStrategy(jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy) ForkPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait) HashSet(java.util.HashSet) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)

Example 2 with BitbucketSCMSource

use of com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource in project blueocean-plugin by jenkinsci.

the class BitbucketCloudScmContentProviderTest method mockMbp.

private MultiBranchProject mockMbp(String credentialId, User user) {
    MultiBranchProject mbp = mock(MultiBranchProject.class);
    when(mbp.getName()).thenReturn("pipeline1");
    when(mbp.getParent()).thenReturn(j.jenkins);
    BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
    when(scmSource.getServerUrl()).thenReturn(apiUrl);
    when(scmSource.getCredentialsId()).thenReturn(credentialId);
    when(scmSource.getRepoOwner()).thenReturn("vivekp7");
    when(scmSource.getRepository()).thenReturn("demo1");
    when(mbp.getSCMSources()).thenReturn(Lists.<SCMSource>newArrayList(scmSource));
    // mock blueocean credential provider stuff
    BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
    DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor>(mbp);
    properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
    Domain domain = mock(Domain.class);
    when(domain.getName()).thenReturn(BitbucketCloudScm.DOMAIN_NAME);
    when(folderProperty.getDomain()).thenReturn(domain);
    when(mbp.getProperties()).thenReturn(properties);
    return mbp;
}
Also used : BlueOceanCredentialsProvider(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) AbstractFolderPropertyDescriptor(com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor) Domain(com.cloudbees.plugins.credentials.domains.Domain) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) AbstractFolderProperty(com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)

Example 3 with BitbucketSCMSource

use of com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource in project blueocean-plugin by jenkinsci.

the class BitbucketCloudScmContentProviderTest method checkScmProperties.

@Test
public void checkScmProperties() throws Exception {
    // ensure cloud provider works with cloud multibranch pipeline
    String credentialId = createCredential(BitbucketCloudScm.ID, authenticatedUser);
    MultiBranchProject mbp = mockMbp(credentialId);
    ScmContentProvider provider = new BitbucketCloudScmContentProvider();
    // unfortunately overriding the apiUrl for WireMock returns a "localhost" URL here, so we mock the call
    when(((BitbucketSCMSource) mbp.getSCMSources().get(0)).getServerUrl()).thenReturn(BitbucketCloudScm.API_URL);
    assertTrue(provider.support(mbp));
    assertEquals(provider.getScmId(), BitbucketCloudScm.ID);
    assertEquals(provider.getApiUrl(mbp), BitbucketCloudScm.API_URL);
    // ensure server provider doesn't work with cloud multibranch pipeline
    provider = new BitbucketServerScmContentProvider();
    assertFalse(provider.support(mbp));
}
Also used : BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) ScmContentProvider(io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider) MultiBranchProject(jenkins.branch.MultiBranchProject) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) BitbucketServerScmContentProvider(io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with BitbucketSCMSource

use of com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource 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())).post("/organizations/jenkins/pipelines/").data(ImmutableMap.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketPipelineCreateRequest", "scmConfig", ImmutableMap.of("id", BitbucketServerScm.ID, "credentialId", credentialId, "uri", apiUrl, "config", ImmutableMap.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) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) 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)

Example 5 with BitbucketSCMSource

use of com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource in project blueocean-plugin by jenkinsci.

the class BitbucketServerScmContentProviderTest method mockMbp.

private MultiBranchProject mockMbp(String credentialId, User user) {
    MultiBranchProject mbp = mock(MultiBranchProject.class);
    when(mbp.getName()).thenReturn("pipeline1");
    when(mbp.getParent()).thenReturn(j.jenkins);
    BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
    when(scmSource.getServerUrl()).thenReturn(apiUrl);
    when(scmSource.getCredentialsId()).thenReturn(credentialId);
    when(scmSource.getRepoOwner()).thenReturn("TESTP");
    when(scmSource.getRepository()).thenReturn("pipeline-demo-test");
    when(mbp.getSCMSources()).thenReturn(Lists.<SCMSource>newArrayList(scmSource));
    // mock blueocean credential provider stuff
    BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
    DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor>(mbp);
    properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(user.getId(), credentialId, BlueOceanCredentialsProvider.createDomain(apiUrl)));
    Domain domain = mock(Domain.class);
    when(domain.getName()).thenReturn(BitbucketServerScm.DOMAIN_NAME);
    when(folderProperty.getDomain()).thenReturn(domain);
    when(mbp.getProperties()).thenReturn(properties);
    return mbp;
}
Also used : BlueOceanCredentialsProvider(io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider) DescribableList(hudson.util.DescribableList) MultiBranchProject(jenkins.branch.MultiBranchProject) AbstractFolderPropertyDescriptor(com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor) Domain(com.cloudbees.plugins.credentials.domains.Domain) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) AbstractFolderProperty(com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)

Aggregations

BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)5 MultiBranchProject (jenkins.branch.MultiBranchProject)4 AbstractFolderProperty (com.cloudbees.hudson.plugins.folder.AbstractFolderProperty)2 AbstractFolderPropertyDescriptor (com.cloudbees.hudson.plugins.folder.AbstractFolderPropertyDescriptor)2 BranchDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait)2 ForkPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait)2 OriginPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait)2 Domain (com.cloudbees.plugins.credentials.domains.Domain)2 DescribableList (hudson.util.DescribableList)2 BlueOceanCredentialsProvider (io.jenkins.blueocean.rest.impl.pipeline.credential.BlueOceanCredentialsProvider)2 CleanAfterCheckoutTrait (jenkins.plugins.git.traits.CleanAfterCheckoutTrait)2 CleanBeforeCheckoutTrait (jenkins.plugins.git.traits.CleanBeforeCheckoutTrait)2 LocalBranchTrait (jenkins.plugins.git.traits.LocalBranchTrait)2 Test (org.junit.Test)2 BitbucketSCMSourceBuilder (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceBuilder)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BitbucketServerScmContentProvider (io.jenkins.blueocean.blueocean_bitbucket_pipeline.server.BitbucketServerScmContentProvider)1 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)1 ScmContentProvider (io.jenkins.blueocean.rest.impl.pipeline.ScmContentProvider)1 HashSet (java.util.HashSet)1