'how to set jenkins changeset exclude setting

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.



Solution 1:[1]

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"
}

Solution 2:[2]

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).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Simon M?Kenzie
Solution 2 crash