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

2

12

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
Consanguineous answered 29/9, 2016 at 10:5 Comment(0)
E
1

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-).*
Empress answered 29/9, 2016 at 12:7 Comment(1)
Thanks for your answer. Unfortunately if I filter PR-.* nothing is scannedConsanguineous
A
9

You can just separate your terms with a space. For your include try:

master PR-*
Arundinaceous answered 9/3, 2017 at 12:47 Comment(1)
This somehow works, but also isn't the behavior I was looking for. Now the branches disappear completely. I was looking for a solution where the branches are still shown and manual branch triggering is possible, but Jenkins won't build the branches automatically by default. Any ideas how to achieve that?Arielariela
E
1

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-).*
Empress answered 29/9, 2016 at 12:7 Comment(1)
Thanks for your answer. Unfortunately if I filter PR-.* nothing is scannedConsanguineous

© 2022 - 2024 — McMap. All rights reserved.