feat: add utils.hasChanges() utility method

This commit is contained in:
wpetit 2023-11-29 12:20:39 +01:00
parent fca4ac23d6
commit 170f143b00
1 changed files with 18 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
import org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.ChangeSetConditional
void when(Boolean condition, body) { void when(Boolean condition, body) {
Map config = [:] Map config = [:]
@ -97,3 +98,20 @@ List<String> getProjectVersionTags(String overrideChannel = '') {
Boolean isPR() { Boolean isPR() {
return env.BRANCH_NAME ==~ /^PR-.*$/ return env.BRANCH_NAME ==~ /^PR-.*$/
} }
def hasChanges(String pattern) {
def changeLogSets = currentBuild.changeSets
def conditional = new ChangeSetConditional(pattern)
for (set in changeLogSets) {
def entries = set.items
for (entry in entries) {
if (conditional.changeSetMatches(entry, pattern, true)) {
return true;
}
}
}
return false;
}