4

I'd like to know if there is something opposite to changeset in Jenkins. For example, in the doc (https://www.jenkins.io/doc/book/pipeline/syntax/), an example is given for changeset setting:

when { changeset pattern: ".TEST\\.java", comparator: "REGEXP" } or when { changeset pattern: "*/*TEST.java", caseSensitive: true }

I'd like to know if I can set "changeset exclude" patterns so that the files match this pattern will not trigger certain stages.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Johnzy
  • 135
  • 1
  • 11

2 Answers2

3

You can use a negative lookahead regex pattern to create a changeset filter that excludes certain paths, for example:

when {
  changeset pattern: '^(?!.*\.TEST\.java).*', comparator: "REGEXP"
}
Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
1

I haven't tried it by myself, but surrounding the condition with not{} should do the trick:

when {
  not {
    changeset pattern: "*/*TEST.java", caseSensitive: true
  }
}

See Pipeline Syntax (when) (scroll down to not).

crash
  • 603
  • 4
  • 11
  • 3
    There is a problem doing it this way: If I have made multiple changes, both in the changeset and not in the changeset, then the stages will not execute(changeset become TRUE, not{} makes it FALSE, so the when condition will not meet). Any solution to work around it? – Johnzy May 30 '20 at 02:40
  • I don’t fully understand what you trying to archive, but you can combine multiple conditions with `anyOf {}` and `allOf {} `. – crash May 30 '20 at 18:03