Issue
I would like to access changelogs in a Pipeline job.
Environment
- CloudBees Jenkins Enterprise
- Jenkins
Related Issue(s)
JENKINS-30412
Blacklisting RunWrapper.getRawBuild
Resolution
Pipeline Supporting APIs Plugin 2.2 or above
You can use
currentBuild.changeSets
in a sandboxed build as you could see in the following example of Git:
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}"
}
}
}
Pipeline Supporting APIs Plugin older than 2.2
You can use
currentBuild.rawBuild.changeSets
but this is not accessible from the sandbox. Following is an example of Git for a non-sandboxed build:
def changeLogSets = currentBuild.rawBuild.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}"
}
}
}
14 Comments