use of com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait 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.BranchDiscoveryTrait 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));
}
Aggregations