how to set jenkins changeset exclude setting

Viewed 1462

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.

2 Answers

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

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

Related