The only way I found to achieve that it's using "when" expression of "stage" with a function I've built to check if thing changed.
when {
expression {
FSTChangePatterns.any{pattern -> sideCars.areFilesChanged(pattern)}
}
}
Where the areFilesChanged is:
// There is a bug in the changeset Jenkins command: https://issues.jenkins-ci.org/browse/JENKINS-44849
// ---
// It returns true if the list of changed files in the PR matches the grep pattern passed
// NOTE: it will always returns true in case the build is running on a branch and not on a PR
// because we always want to run a full pipelines on master, release and feature branches
def areFilesChanged(grepPattern) {
if (!env.
CHANGE_TARGET) return
true
sh(
// NOTE: the triple-dot are necessary to get the same diff result shown by GitHub PRs
script: "git diff origin/${env.CHANGE_TARGET}...HEAD --name-only | grep '${grepPattern}'",
returnStatus:
true
) ==
0
}
Cheers,
Gianluca.