Hi luckyhorang - 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] [Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Test changeset)
[Pipeline] echo
The changeset test worked!!
[Pipeline] }
[Pipeline] [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 [Pipeline] }
[Pipeline] [Pipeline] }
[Pipeline] [Pipeline] }
[Pipeline] [Pipeline] }
[Pipeline] [Pipeline] End of Pipeline
Finished: SUCCESS
I did not understand the changeset regex syntax so you may have to ask others about that.
Hi luckyhorang - Yes but I do not know how useful it will be. The following uses 'changeset' to test for the 'Jenkinsfile':
Note that the text at the end attempts to display the contents of the changeset. In my case the output was:
I did not understand the changeset regex syntax so you may have to ask others about that.