From 170f143b004e87ddf9a9a4b71f0942169bd4bbf5 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 29 Nov 2023 12:20:39 +0100 Subject: [PATCH] feat: add utils.hasChanges() utility method --- vars/utils.groovy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/vars/utils.groovy b/vars/utils.groovy index aaa011a..52067fe 100644 --- a/vars/utils.groovy +++ b/vars/utils.groovy @@ -1,4 +1,5 @@ import org.jenkinsci.plugins.pipeline.modeldefinition.Utils +import org.jenkinsci.plugins.pipeline.modeldefinition.when.impl.ChangeSetConditional void when(Boolean condition, body) { Map config = [:] @@ -97,3 +98,20 @@ List getProjectVersionTags(String overrideChannel = '') { Boolean isPR() { 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; +} \ No newline at end of file