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;
}
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;
}
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));
}
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));
}
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;
}
Aggregations