When I setup a Jenkins Multibranch Pipeline through the UI the Behaviours section allows me to specify what gets built. We add "Discover pull requests from origin" so PRs get built, and "Discover branches" to build branches.
But for one build which takes well over an hour we'd like to disable the branch building so it's only built for PRs (our builds run on AWS and we don't want the additional expense). Unfortunately we've found that when we remove "Discover branches" it also stops building main
.
What we'd like to have is for Jenkins to:
- Build PRs.
- Build
main
. - Ignore all other branches.
Is this possible?
Update: I tried wildcards as suggested below but it doesn't work. I added "Filter by name (with regular expression)" with the regex set to "^(?:.main).$" (basically match main
and nothing else) but no difference.
Then I added back "Discover branches" and it successfully found main
and built that but no other branches.
However, when I created a PR called test-build
it also ignored this. Seems like the wildcard works on everything. Since we don't have a naming convention this won't work.