Search in sources :

Example 1 with CleanAfterCheckoutTrait

use of jenkins.plugins.git.traits.CleanAfterCheckoutTrait in project blueocean-plugin by jenkinsci.

the class GithubPipelineCreateRequest method createSource.

@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
    // Update endpoint only if its GitHub Enterprise
    if (scmConfig.getId().equals(GithubEnterpriseScm.ID)) {
        updateEndpoints(scmConfig.getUri());
    }
    Set<ChangeRequestCheckoutStrategy> strategies = new HashSet<>();
    strategies.add(ChangeRequestCheckoutStrategy.MERGE);
    return new GitHubSCMSourceBuilder(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.TrustPermission())).withTrait(new OriginPullRequestDiscoveryTrait(strategies)).withTrait(new CleanBeforeCheckoutTrait()).withTrait(new CleanAfterCheckoutTrait()).withTrait(new LocalBranchTrait()).build();
}
Also used : ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) GitHubSCMSourceBuilder(org.jenkinsci.plugins.github_branch_source.GitHubSCMSourceBuilder) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) ChangeRequestCheckoutStrategy(jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) HashSet(java.util.HashSet)

Example 2 with CleanAfterCheckoutTrait

use of jenkins.plugins.git.traits.CleanAfterCheckoutTrait 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 CleanAfterCheckoutTrait

use of jenkins.plugins.git.traits.CleanAfterCheckoutTrait in project blueocean-plugin by jenkinsci.

the class BitbucketPipelineCreateRequest method createSource.

@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@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.get().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) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

CleanAfterCheckoutTrait (jenkins.plugins.git.traits.CleanAfterCheckoutTrait)3 CleanBeforeCheckoutTrait (jenkins.plugins.git.traits.CleanBeforeCheckoutTrait)3 LocalBranchTrait (jenkins.plugins.git.traits.LocalBranchTrait)3 HashSet (java.util.HashSet)2 ChangeRequestCheckoutStrategy (jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy)2 BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)1 BitbucketSCMSourceBuilder (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceBuilder)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 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 JenkinsLocationConfiguration (jenkins.model.JenkinsLocationConfiguration)1 GitSCMSource (jenkins.plugins.git.GitSCMSource)1 BranchDiscoveryTrait (jenkins.plugins.git.traits.BranchDiscoveryTrait)1 SCMSourceTrait (jenkins.scm.api.trait.SCMSourceTrait)1 BranchDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait)1 ForkPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait)1 GitHubSCMSourceBuilder (org.jenkinsci.plugins.github_branch_source.GitHubSCMSourceBuilder)1 OriginPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait)1