Currently, using the setup displayed below, Jenkins builds master
and all *-preview
branches. Using Branches to build, is it possible for Jenkins to exclude a single *-preview
branch such as exclude-this-branch-preview
while building all remaining *-preview
branches?
Asked
Active
Viewed 1,362 times
2

DanCat
- 2,504
- 2
- 19
- 26
2 Answers
3
You can use regex by specifying a semi-colon before
:^(?!exclude-this-branch-preview).*-preview$
From the help:
:<regular expression>
The syntax is of the form: :regexp. Regular expression syntax in branches to
build will only build those branches whose names match the regular expression.
Examples:
:^(?!(origin/prefix)).*
matches: origin or origin/master or origin/feature
does not match: origin/prefix or origin/prefix_123 or origin/prefix-abc
:origin/release-\d{8}
matches: origin/release-20150101
does not match: origin/release-2015010 or origin/release-201501011 or
origin/release-20150101-something
:^(?!origin/master$|origin/develop$).*
matches: origin/branch1 or origin/branch-2 or origin/master123 or
origin/develop-123
does not match: origin/master or origin/develop

Cole9350
- 5,444
- 2
- 34
- 50
-
What does the leading `?` on `:^(?!exclude-this-branch-preview).*-preview$` imply? – DanCat Jul 22 '17 at 15:29
-
1@DanCat The `?!` is negative look ahead, which basically means must not match. https://stackoverflow.com/questions/12210807/what-does-mean – Cole9350 Jul 25 '17 at 13:53
2
:^(?!(<the branch name to be excluded with out angular braces>)).*
Put this in the branches to build and try SCM polling. Its a regular expression, self explanatory.

Vighnesh Pai
- 1,795
- 1
- 14
- 38