Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Plugin for Jenkins v2.138.2 or later, that triggers job builds on Bitbucket's push and pull request events.

License

NotificationsYou must be signed in to change notification settings

jenkinsci/bitbucket-push-and-pull-request-plugin

Build StatusContributorsJenkins PluginGitHub releaseJenkins Plugin InstallsGitter

jenkins logo

Compatibility

Starting from version 3.2.0 the Plugin is compatible with:

  • Jenkins version: >=2.401.3
  • Java version:11

Starting from version 3.0.0 the Plugin is compatible with:

  • Jenkins version: >=2.361.4
  • Java version:11

The version 2.x.x of the Plugin is compatible with:

  • Jenkins >= v2.138.2
  • Java 8

Introduction

Plugin for Jenkinsv2.361.4 or later, that triggers builds on Bitbucket's push and pull requests events.

Some of the features introduced by Bitbucket Push and Pull Request are:

  • build state notification
  • support of pull requests for Bitbucket cloud (rest api v2.x+ with mercurial and git) and bitbucket Server (fromversion 5.14 to version 7.21 - with git)
  • support of pushs for Bitbucket cloud (rest api v2.x+ with mercurial and git) and Bitbucket server (from version 5.14to version 7.21 - with git)
  • usage of Gson instead of net.sf.json.JSONObject
  • Introduction of models and major security improvements

Bitbucket Push and Pull Request supports the

  • Bitbucket cloud rest api v2.x+ and later (with git and mercurial repos)
  • Bitbucket server 5.14+ and later (with git repos)

Before you start

The version 2.x.x of the Plugin is compatible with:

  • Jenkins >= v2.138.2
  • Java 8

Otherwise, The version 3.x.x of the Plugin compatible with:

  • Jenkins version: >= 2.361.4
  • Java version: 11

Bitbucket Push And Pull Request Plugin will not work if the old Bitbucket pluginhttps://plugins.jenkins.io/bitbucketis still installed. So, please de-install from Jenkins the previous Bitbucket plugin if you want to use this new one.

Reason is: both plugins use the same webhook endpoint and Jenkins gives priority to the old Bitbucket plugin, due to thelexical ordering used by Stapler to dispatch the request.

In case you want to use both plugins on the same Jenkins instance, you must:

  • override the default webhook endpoint "bitbucket-hook" in the Jenkins Global Configurations of the Bitbucket Push andPull Request Plugin using a fresh new webhook - let's say: "bitbucket-ppr-webhook".This webhook has to be a newone, consumed only by the Bitbucket Push and Pull Request Plugin, in order to avoid conflicts with other plugins
  • After that, restart Jenkins
  • and configure the Bitbucket Cloud / Server webhooks accordingly to the new webhook endpoint (in our example: "bitbucket-ppr-webhook")

Configuration

Configure the webhook

Configure your Bitbucket repository adding a webhook in the settings page. In the URL field (see image, at point A) addyour JENKINS_URL followed by "/bitbucket-hook/" (forexamplehttps://my-jenkins.on-my-planet-far-away.com/bitbucket-hook/) Credentials for the webhook endpoint are notrequired, the trailing slash is mandatory.

For more specific infos about managing webhooks please consult:

Configure the Global Configurations of the Plugin

in theJenkins Global Configurations:

  1. you can override the default webhook endpoint "/bitbucket-hook/" consumed by the plugin

  2. you can configure a single job to be triggered exclusively. That overrides the default behavior of having a dedicatedendpoint (+ some internal matching logic) for ALL pipelines to be triggered via this plugin. In case of anon-existing job a WARNING will be logged at global jenkins log. You can omit this feature by simply leaving thisfield blank.

  3. you can disable the build status notifications propagation.

  4. you can choose what build key to use for build status propagation

  5. you can set global credentials used by the plugin for the state notification

  6. you can set a propagation url to send the build status notification to a different url than the one used for thewebhook

example global config jenkins bb ppr 1

Configure your Jenkins job

  1. Configure the Bitbucket Repository under the Source Code Management with your credentials. For git:example config gitIn case you are using Mercurial instead of git, configure it as follows:exampel config mercurialPlease note: the branch, related to the events which trigger the builds, must be specified in the field Revision.

  2. Now activate the plugin in your job selecting the "Build with Bitbucket Push and Pull Request Plugin" option in theBuild Triggers pane.

  3. you can set a propagation url to send the build status notification to a different url than the one used for thewebhook. Note: this will override the one in the global configuration.

  4. Run the first job manually

Authentication for state notification and generally when using the Bitbucket REST API

TYPEBB CLOUDBB SERVERJENKINS CREDENTIALSNOTES
Username & PasswordXXUsername with passworddeprecated by bbc, will be removed in march 2022
HTTP access token-XSecret Textlearn more about HTTP tokens
OAuth consumersX-Secret TextOauth Consumers example config
  1. you can set globally the credentials used by the plugin for the state notification
  2. you can set for each job the credentials used by the plugin for the state notification, overwriting the globalcredentials
  3. you you don't set nothing the plugin will try to use the credentials used by the git plugin

Bitbucket Events supported by the plugin

FILTERBB CLOUDBB SERVERNOTES
Pull Request CreatedXX
Pull Request UpdatedXX
Pull Request DeclinedXX
Pull Request MergedXX
PushXX
Comment CreatedXX
Comment UpdatedX-If a user updates the same comment with not much time in between, Bitbucket only sends the event request the first time the comment is updated.
Comment DeletedX-

Interaction with the git plugin

This plugin forwards events from Bitbucket to the Git plugin, which manages all Git-related operations such as cloning,checking out, and fetching repositories. By delegating Git tasks to the Git plugin, this plugin focuses solely onhandling Bitbucket events and trigger logic.

Some examples

example config jenkins bb ppr 1example config jenkins bb ppr 2example config jenkins bb ppr 3example config jenkins bb ppr 4

Troubleshooting: Some important aspects to keep in mind

About the initialization of the plugin

The Bitbucket Push and Pull Request Plugin (BBPPR Plugin) uses theGit Plugin to handle with the gitrepositories managed by BitBucket. More in details:

  1. The user initiliazes a new job starting manually a build.
  2. TheGit Plugin clones the repository declared in the job fetching the branches as defined in theBranchSpecifier filter field.
  3. Due to the fact that each branch is new, theBBPPR Pluginsees everywhere changes and, as a consequence, the *BBPPR Plugin* starts for each new fetched branch a job.
  4. It's also important to keep in mind that the filters on the branches specified by theBBPPR Plugin in its *Allowed Branches* field, are not applied in the initialization phase, because they are only active for jobstriggered through the BitBucket webhook (and not for the ones, which are built manually).

About the filters on the branches

Talking generally, there are two filters used to 'control the branches':

  • theGit plugin filter on the branches: a kind of general filter applied at job level.

  • theBBPPR plugin filter: a specific one, that acts at trigger level and that is there because the user can have ina job more triggers than only one.

  • Important is to keep in mind, that you cannot trigger events on branches that are excluded from the Git Plugin filter.It has the precedence because it defines (fetches) the branches, that can be accessed by theBBPPR plugin.

  • Moreover, the way in which the matching is done is the same for both plugins, becausewe are using for the matchingthe public method given to disposal from the Git Plugin.The reason for that is the wish to guarantee consistency between the two plugins, at least regarding the way in whichbranches are matched. This all means also, that we are not implementing the matching logic.

  • As you see from the code:return matches(allowedBranches, bitbucketAction.getTargetBranch(), null);, the matching isbetween the string you specified (allowedBranches) and thetarget branch specified in the payload sent fromBitBucket (bitbucketAction.getTargetBranch()). This means thatThe filter is not on the source branch, but on thetarget branch.

  • You can find al lot of examples in this testclass:BitBucketPPRPullRequestCreatedActionFilterTest.java

Environment variables

NAMEVALUESCOPEBB TYPENOTES
BITBUCKET_TARGET_BRANCHtarget branchPR + PC + S
BITBUCKET_ACTORactor namePR + PC + S
BITBUCKET_PAYLOADComplete payload as json stringPR + PC + S
BITBUCKET_X_EVENTx-event which triggered the pluginPR + PC + S
BITBUCKET_SOURCE_BRANCHsource branchPRC + S
BITBUCKET_PULL_REQUEST_TITLEPR titlePRC + S
BITBUCKET_PULL_REQUEST_IDidPRC + S
BITBUCKET_PULL_REQUEST_LINKlinkPRC + S
BITBUCKET_PULL_REQUEST_DESCRIPTIONPR descriptionPRC + S
BITBUCKET_PULL_REQUEST_COMMENT_TEXTComment of BB Cloud Pull RequestPRC + S
BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_SOURCE_BRANCHLatest commit hash on the source branchPRC + S
BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_TARGET_BRANCHLatest commit hash on the target branchPRC + S
BITBUCKET_REPOSITORY_UUIDRepository identifierPC
BITBUCKET_REPOSITORY_IDRepository identifierPS
BITBUCKET_REPOSITORY_URLRepository URLPRC
REPOSITORY_LINKRepository linkPCDeprecated: to remove in 2.6
REPOSITORY_NAMERepository namePSDeprecated: to remove in 2.6

Dsl Job actions for Bitbucket Push and Pull Request Trigger

bitbucketTriggers {// For Bitbucket Cloud    repositoryPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String)    repositoryPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String,isToApprove:boolean)    repositoryPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String,isToApprove:boolean,triggerOnlyIfTagPush:boolean)    pullRequestApprovedAction(onlyIfReviewersApproved:boolean)    pullRequestApprovedAction(onlyIfReviewersApproved:boolean,allowedBranches:String)    pullRequestApprovedAction(onlyIfReviewersApproved:boolean,allowedBranches:String,isToApprove:boolean)    pullRequestCreatedAction()    pullRequestCreatedAction(allowedBranches:String)    pullRequestCreatedAction(allowedBranches:String,isToApprove:String)    pullRequestUpdatedAction()    pullRequestUpdatedAction(allowedBranches:String)    pullRequestUpdatedAction(allowedBranches:String,isToApprove:String)    pullRequestMergedAction()    pullRequestMergedAction(allowedBranches:String)    pullRequestMergedAction(allowedBranches:String,isToApprove:String)    pullRequestDeclinedAction()    pullRequestDeclinedAction(allowedBranches:String)    pullRequestCommentCreatedAction()    pullRequestCommentCreatedAction(allowedBranches:String)    pullRequestCommentCreatedAction(allowedBranches:String,commentFilter:String)// CommentFilter is java a regex expression    pullRequestCommentUpdatedAction()    pullRequestCommentUpdatedAction(allowedBranches:String)    pullRequestCommentUpdatedAction(allowedBranches:String,commentFilter:String)// CommentFilter is java a regex expression    pullRequestCommentDeletedAction()    pullRequestCommentDeletedAction(allowedBranches:String)// For Bitbucket Server// note: flag `isToApprove` has no effect yet    repositoryServerPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String)    repositoryServerPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String,isToApprove:boolean)    repositoryServerPushAction(triggerAlsoIfTagPush:boolean,triggerAlsoIfNothingChanged:boolean,allowedBranches:String,isToApprove:boolean,triggerOnlyIfTagPush:boolean)    pullRequestServerApprovedAction(onlyIfReviewersApproved:boolean)    pullRequestServerApprovedAction(onlyIfReviewersApproved:boolean,allowedBranches:String)    pullRequestServerApprovedAction(onlyIfReviewersApproved:boolean,allowedBranches:String,isToApprove:boolean)    pullRequestServerCreatedAction()    pullRequestServerCreatedAction(allowedBranches:String)    pullRequestServerCreatedAction(allowedBranches:String,isToApprove:boolean)    pullRequestServerUpdatedAction()    pullRequestServerUpdatedAction(allowedBranches:String)    pullRequestServerUpdatedAction(allowedBranches:String,isToApprove:boolean)    pullRequestServerSourceUpdatedAction()    pullRequestServerSourceUpdatedAction(allowedBranches:String)    pullRequestServerSourceUpdatedAction(allowedBranches:String,isToApprove:boolean)    pullRequestServerMergedAction()    pullRequestServerMergedAction(allowedBranches:String)    pullRequestServerMergedAction(allowedBranches:String,isToApprove:boolean)    pullRequestServerDeclinedAction()    pullRequestServerDeclinedAction(allowedBranches:String)    pullRequestServerCommentCreatedAction()    pullRequestServerCommentCreatedAction(allowedBranches:String)    pullRequestServerCommentCreatedAction(allowedBranches:String,commentFilter:String)}

Dsl Job snippets

Valid for freestyle jobs and pipeline jobs (until job-dsl plugin v1.76, deprecated in v1.77 for pipeline jobs)

// pullRequestCreatedAction()job('example-pull-request-created') {    triggers {        bitbucketTriggers {            pullRequestCreatedAction()        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created')    }}// pullRequestCreatedAction() with filter on branchesjob('example-pull-request-created-with-filter-on-branches') {    triggers {        bitbucketTriggers {            pullRequestCreatedAction("master")        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created with filter on branches')    }}// pullRequestCreatedAction() with filter on branches// and eventually approve Pull Request in BB after the job is donejob('example-pull-request-created-with-filter-on-branches-and-is-to-approve') {    triggers {        bitbucketTriggers {            pullRequestCreatedAction("master",true)        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created with filter on branches')    }}// pullRequestUpdatedAction()job('example-pull-request-updated') {    triggers {        bitbucketTriggers {            pullRequestUpdatedAction()        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated')    }}// pullRequestUpdatedAction() wiht filter on branchesjob('example-pull-request-updated-with-filter-on-branches') {    triggers {        bitbucketTriggers {            pullRequestUpdatedAction("master")        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated with filter on branches')    }}// pullRequestUpdatedAction() wiht filter on branches// and eventually approve Pull Request in BB after the job is donejob('example-pull-request-updated-with-filter-on-branches') {    triggers {        bitbucketTriggers {            pullRequestUpdatedAction("master",true)        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated with filter on branches')    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved)    job('example-pull-request-approved') {        triggers {            bitbucketTriggers {                pullRequestApprovedAction(false)            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved')        }    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved) with filter on branches    job('example-pull-request-approved-with-filter-on-branches') {        triggers {            bitbucketTriggers {                pullRequestApprovedAction(false,"master")            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved with filter on branches')        }    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved) with filter on branches// and eventually approve Pull Request in BB after the job is done    job('example-pull-request-approved-with-filter-on-branches') {        triggers {            bitbucketTriggers {                pullRequestApprovedAction(false,"master",true)            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved with filter on branches')        }    }// pullRequestMergedAction()    job('example-pull-request-merged') {        triggers {            bitbucketTriggers {                pullRequestMergedAction()            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged')        }    }// pullRequestMergedAction() with filter on branches    job('example-pull-request-merged-with-filter-on-branches') {        triggers {            bitbucketTriggers {                pullRequestMergedAction("master")            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged with filter on branches')        }    }// pullRequestMergedAction() with filter on branches// and eventually approve Pull Request in BB after the job is done    job('example-pull-request-merged-with-filter-on-branches') {        triggers {            bitbucketTriggers {                pullRequestMergedAction("master")            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged with filter on branches')        }    }// repositoryPushAction(boolean triggerAlsoIfTagPush, boolean triggerAlsoIfNothingChanged, String allowedBranches)    job('example-push') {        triggers {            bitbucketTriggers {                repositoryPushAction(false,true,"master")            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START push')        }    }// repositoryPushAction(boolean triggerAlsoIfTagPush, boolean triggerAlsoIfNothingChanged, String allowedBranches)// and eventually approve Pull Request in BB after the job is done    job('example-push') {        triggers {            bitbucketTriggers {// and eventually approve Pull Request in BB after the job is done                repositoryPushAction(false,true,"master",true)            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START push')        }    }// combination of triggers is also possible    job('example-pull-request-created-updated') {        triggers {            bitbucketTriggers {                pullRequestCreatedAction()                pullRequestUpdatedAction()                pullRequestMergedAction("master")            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request created')        }    }

Valid for pipeline with job-dsl 1.77+ (and before)

Note that this may require an additional script approval, the seed job failing with a message similar to:

ERROR: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (javaposse.jobdsl.dsl.jobs.WorkflowJob bitbucketTrigger script$_run_closure1$_closure5$_closure24$_closure29$_closure30$_closure31)
// pullRequestCreatedAction()job('example-pull-request-created') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestCreatedActionFilter {                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created')    }}// pullRequestCreatedAction() with filter on branchesjob('example-pull-request-created-with-filter-on-branches') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestCreatedActionFilter {                                    allowedBranches("master")                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created with filter on branches')    }}// pullRequestCreatedAction() with filter on branches// and eventually approve Pull Request in BB after the job is donejob('example-pull-request-created-with-filter-on-branches-and-is-to-approve') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestCreatedActionFilter {                                    allowedBranches("master")                                    isToApprove(true)                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request created with filter on branches')    }}// pullRequestUpdatedAction()job('example-pull-request-updated') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestUpdatedActionFilter {                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated')    }}// pullRequestUpdatedAction() wiht filter on branchesjob('example-pull-request-updated-with-filter-on-branches') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestUpdatedActionFilter {                                    allowedBranches("master")                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated with filter on branches')    }}// pullRequestUpdatedAction() wiht filter on branches// and eventually approve Pull Request in BB after the job is donejob('example-pull-request-updated-with-filter-on-branches') {    properties {        pipelineTriggers {            triggers {                bitBucketTrigger {                    triggers {                        bitBucketPPRPullRequestTriggerFilter {                            actionFilter {                                bitBucketPPRPullRequestUpdatedActionFilter {                                    allowedBranches("master")                                    isToApprove(true)                                }                            }                        }                    }                }            }        }    }    scm {        git {            remote {                url("https://git.company.domain/scm/~username/telegram.git")            }        }    }    steps {        shell('echo START pull request updated with filter on branches')    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved)    job('example-pull-request-approved') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestApprovedActionFilter {                                        triggerOnlyIfAllReviewersApproved(false)                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved')        }    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved) with filter on branches    job('example-pull-request-approved-with-filter-on-branches') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestApprovedActionFilter {                                        triggerOnlyIfAllReviewersApproved(false)                                        allowedBranches("master")                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved with filter on branches')        }    }// pullRequestApprovedAction(boolean onlyIfReviewersApproved) with filter on branches// and eventually approve Pull Request in BB after the job is done    job('example-pull-request-approved-with-filter-on-branches') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestApprovedActionFilter {                                        triggerOnlyIfAllReviewersApproved(false)                                        allowedBranches("master")                                        isToApprove(true)                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request approved with filter on branches')        }    }// pullRequestMergedAction()    job('example-pull-request-merged') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestMergedActionFilter {                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged')        }    }// pullRequestMergedAction() with filter on branches    job('example-pull-request-merged-with-filter-on-branches') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestMergedActionFilter {                                        allowedBranches("master")                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged with filter on branches')        }    }// pullRequestMergedAction() with filter on branches// and eventually approve Pull Request in BB after the job is done    job('example-pull-request-merged-with-filter-on-branches') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestMergedActionFilter {                                        allowedBranches("master")                                        isToApprove(true)                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request merged with filter on branches')        }    }// repositoryPushAction(boolean triggerAlsoIfTagPush, boolean triggerAlsoIfNothingChanged, String allowedBranches)    job('example-push') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRRepositoryTriggerFilter {                                actionFilter {                                    bitBucketPPRRepositoryPushActionFilter {                                        triggerAlsoIfTagPush(false)                                        triggerAlsoIfNothingChanged(true)                                        allowedBranches("master")                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START push')        }    }// repositoryPushAction(boolean triggerAlsoIfTagPush, boolean triggerAlsoIfNothingChanged, String allowedBranches)// and eventually approve Pull Request in BB after the job is done    job('example-push') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {// and eventually approve Pull Request in BB after the job is done                        triggers {                            bitBucketPPRRepositoryTriggerFilter {                                actionFilter {                                    bitBucketPPRRepositoryPushActionFilter {                                        triggerAlsoIfTagPush(false)                                        triggerAlsoIfNothingChanged(true)                                        allowedBranches("master")                                        isToApprove(true)                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START push')        }    }// combination of triggers is also possible    job('example-pull-request-created-updated') {        properties {            pipelineTriggers {                triggers {                    bitBucketTrigger {                        triggers {                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestCreatedActionFilter {                                    }                                }                            }                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestUpdatedActionFilter {                                    }                                }                            }                            bitBucketPPRPullRequestTriggerFilter {                                actionFilter {                                    bitBucketPPRPullRequestMergedActionFilter {                                        allowedBranches("master")                                    }                                }                            }                        }                    }                }            }        }        scm {            git {                remote {                    url("https://git.company.domain/scm/~username/telegram.git")                }            }        }        steps {            shell('echo START pull request created')        }    }

Second (more verbose) valid dsl for freestyle jobs

Below example is for Pull-request updated (that shall be approved) on BitBucket Cloud, for a FreeStyle job.All the above examples can be adapted with the same paradigm.

freeStyleJob('test-job') {    triggers {        bitBucketTrigger {            triggers {                bitBucketPPRPullRequestTriggerFilter {                    actionFilter {                        bitBucketPPRPullRequestUpdatedActionFilter {                            isToApprove(true)                        }                    }                }            }        }    }}

Pipeline script

Example of pipeline code for building on pull-request and push events.

properties([        pipelineTriggers([                [                        $class  :'BitBucketPPRTrigger',triggers: [                                [                                        $class      :'BitBucketPPRPullRequestTriggerFilter',actionFilter: [                                                $class:'BitBucketPPRPullRequestCreatedActionFilter',                                        ]                                ],                                [                                        $class      :'BitBucketPPRPullRequestTriggerFilter',actionFilter: [                                                $class:'BitBucketPPRPullRequestApprovedActionFilter',                                        ]                                ],                                [                                        $class      :'BitBucketPPRPullRequestTriggerFilter',actionFilter: [                                                $class:'BitBucketPPRPullRequestUpdatedActionFilter',                                        ]                                ],                                [                                        $class      :'BitBucketPPRPullRequestTriggerFilter',actionFilter: [                                                $class:'BitBucketPPRPullRequestMergedActionFilter',                                        ]                                ],                                [                                        $class      :'BitBucketPPRRepositoryTriggerFilter',actionFilter: [                                                $class                     :'BitBucketPPRRepositoryPushActionFilter',triggerAlsoIfNothingChanged:true,triggerAlsoIfTagPush       :false,allowedBranches            :"",isToApprove                :true                                        ]                                ]                        ]                ]        ])])pipeline {    agent any    stages {        stage('Build') {            steps {                echo'Building...'                echo'Env vars for cloud pull request...'                echo"BITBUCKET_SOURCE_BRANCH${env.BITBUCKET_SOURCE_BRANCH}"                echo"BITBUCKET_TARGET_BRANCH${env.BITBUCKET_TARGET_BRANCH}"                echo"BITBUCKET_PULL_REQUEST_LINK${env.BITBUCKET_PULL_REQUEST_LINK}"                echo"BITBUCKET_PULL_REQUEST_ID${env.BITBUCKET_PULL_REQUEST_ID}"                echo"BITBUCKET_PAYLOAD${env.BITBUCKET_PAYLOAD}"                echo'Env vars for cloud push...'                echo"REPOSITORY_LINK${env.REPOSITORY_LINK}"                echo"BITBUCKET_SOURCE_BRANCH${env.BITBUCKET_SOURCE_BRANCH}"                echo"BITBUCKET_REPOSITORY_URL${env.BITBUCKET_REPOSITORY_URL}"                echo"BITBUCKET_PUSH_REPOSITORY_UUID${env.BITBUCKET_PUSH_REPOSITORY_UUID}"                echo"BITBUCKET_PAYLOAD${env.BITBUCKET_PAYLOAD}"                echo'Env vars for server push...'                echo"REPOSITORY_LINK${env.REPOSITORY_LINK}"                echo"BITBUCKET_SOURCE_BRANCH${env.BITBUCKET_SOURCE_BRANCH}"                echo"BITBUCKET_REPOSITORY_URL${env.BITBUCKET_REPOSITORY_URL}"                echo"BITBUCKET_PUSH_REPOSITORY_UUID${env.BITBUCKET_PUSH_REPOSITORY_UUID}"                echo"BITBUCKET_PAYLOAD${env.BITBUCKET_PAYLOAD}"            }        }    }}

Thanks and Acknowledgments

This plugin is originally based on the Sazo's fork (https://github.com/sazo/bitbucket-plugin)of the Bitbucket plugin:https://plugins.jenkins.io/bitbucket.

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp