Search code examples
bitbucketjenkins-pipelinejenkins-2

Jenkins Bitbucket Branch Source Plugin how to build only master and PR?


I'm using Jenkins 2 with the Bitbucket Branch Source Plugin which scans and builds all the branches and PRs.

My problem is that when I push code to a PR, the branch is built twice (one for the branch and one for the PR). I would like to build only master and PRs.

Do someone knows how to do that ? I can't find any documentation about this.

From the Branch Indexing Log (wihtout filter):

Checking branch branch-name from repo/project
Met criteria
Scheduled build for branch: branch-name
...
Checking PR from repo/project and branch branch-name
Met criteria
Scheduled build for branch: PR-123

Then when I try to filter on PR-* nothing is scanned. I just get:

Checking branch branch-name from repo/project

Solution

  • When you are configuring your Bitbucket sources, you can use Include branches or Exclude branches (in Advanced params) to include/exclude some branches :

    enter image description here

    And based on Bitbucket Branch source plugin source code, both fields takes an Ant regex.

    So assuming all your PR branches start with "pr-" you could use a regex in include branches, e.g. :

    (?:master|pr-).*