Hi,
Is it possible to use changeset syntax ?
For example,
stage ('test') { when { changeset "branchA/folder1/**" } steps { ... } }
Hi Hokwang Lee - Yes but I do not know how useful it will be. The following uses 'changeset' to test for the 'Jenkinsfile':
pipeline { agent { label 'master' } stages { stage("Test changeset"){ when { changeset "**/Jenkinsfile"} steps{ echo "The changeset test worked!!"} } stage("Display changeset?") { steps { script { def changeLogSets = currentBuild.changeSets for (int i = 0; i < changeLogSets.size(); i++) { def entries = changeLogSets[i].items for (int j = 0; j < entries.length; j++) { def entry = entries[j] echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}" def files = new ArrayList(entry.affectedFiles) for (int k = 0; k < files.size(); k++) { def file = files[k] echo " ${file.editType.name} ${file.path}" } } } } }
Note that the text at the end attempts to display the contents of the changeset. In my case the output was:
[Pipeline] } [Pipeline] // stage [Pipeline] withEnv [Pipeline] { [Pipeline] stage [Pipeline] { (Test changeset) [Pipeline] echo The changeset test worked!! [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Display changeset?) [Pipeline] script [Pipeline] { [Pipeline] echo 1734 by super on Thu Jul 11 16:39:02 UTC 2019: Edited [Pipeline] echo edit //streams/main/Jenkinsfile [Pipeline] } [Pipeline] // script [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS
I did not understand the changeset regex syntax so you may have to ask others about that.
Thanks. You can close this case.
Hi Hokwang Lee - Thanks.
I'm trying to get this exact example working, and the when test is failing for some reason despite the other stuff looking OK... any ideas?
[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline]
[Pipeline] // stage[Pipeline] stage[Pipeline] { (Display changeset?)[Pipeline] script[Pipeline]
[Pipeline] // script[Pipeline] }[Pipeline] // stage
See JENKINS-60066 for investigation.