0

I have Jenkins installation (v2.332.2) on windows (AWS) with git plugin and GitHub webhook trigger.

When I hardcode the values of branches such as dd.d or dd.* the webhook triggers build appropriately. I want to be able to build all branches that match a certain pattern for branch names.

E.g.,

  1. origin/18.3
  2. origin/22.1
  3. origin/22.0
  4. origin/29.0
  5. origin/33.2
  6. origin/22.1-release (I don't want to build)
  7. origin/20.3-s36834 (I don't want to build)

I have tried to add the regex in branch specifications multiple ways but to no avail. any help is greatly appreciated.

I have tried the following combinations for branches regex

  1. origin/\d{2}.\d{2}$
  2. origin/\d+.\d+$
  3. \d{2}.\d{2}$
  4. \d+.\d+$
  5. origin/\d{2}*
  6. \d{2}*

enter image description here

enter image description here

enter image description here

torek
  • 448,244
  • 59
  • 642
  • 775
Princy
  • 613
  • 1
  • 6
  • 11
  • 1
    The branch specifier in your screenshot looks more like a _wildcard_ pattern than a regex - are you sure that regexes are supported? – mklement0 Sep 01 '22 at 15:39
  • 1
    It is propably a git _branch pattern_, which is similar to a _shell wildcard_, but has some differences, see [this answer](https://stackoverflow.com/a/41403591/7571258). – zett42 Sep 01 '22 at 17:06
  • @mklement0 that's just the latest screenshot with my hardcoded value for the branch name that worked. It worked for 2* 22.* etc but the moment I specify anything regex, it doesn't get triggered. Those are the regex combination I mentioned above – Princy Sep 01 '22 at 17:24
  • But for my requirements, I think world cards will not suffice. That is my make-shift solution for now – Princy Sep 01 '22 at 17:36
  • 1
    A comment below the linked answer suggests you can use negation, e. g. `origin/*.*[^-]` which would exclude branches with a hyphen like `origin/22.1-release`. – zett42 Sep 01 '22 at 19:24
  • 2
    @zett42: I'm no Jenkins expert, but it appears that Jenkins really does use regex here. (Git is not relevant, it's what Jenkins does that matters.) See, e.g., [How to exclude git branch from building in Jenkins](https://stackoverflow.com/q/21314632/1256452). – torek Sep 02 '22 at 05:06
  • 1
    Thanks, @torek. Judging by one of the answers to the linked question and https://issues.jenkins.io/browse/JENKINS-58804, use of regexes requires _opt-in_, by _prefixing the regex with `:`_. – mklement0 Sep 02 '22 at 13:21

0 Answers0