patternModerate
Get all change logs of since last successful build in Jenkins Pipeline
Viewed 0 times
lastlogssuccessfulalljenkinsbuildsincegetchangepipeline
Problem
In my Jenkins pipeline, I can get change logs of the current build by this.
Is there a way to get all change-logs since last successful build?
def changeLogSets = currentBuild.changeSetsIs there a way to get all change-logs since last successful build?
Solution
You may try something like this:
Additionally, you may try out "Changes Since Last Success Plugin":
https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin
But it will not work together with pipeline, this is a separate approach.
node('my_kubernetes_pod') {
passedBuilds = []
lastSuccessfulBuild(passedBuilds, currentBuild);
def changeLog = getChangeLog(passedBuilds)
echo "changeLog ${changeLog}"
}
def lastSuccessfulBuild(passedBuilds, build) {
if ((build != null) && (build.result != 'SUCCESS')) {
passedBuilds.add(build)
lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
}
}
@NonCPS
def getChangeLog(passedBuilds) {
def log = ""
for (int x = 0; x < passedBuilds.size(); x++) {
def currentBuild = passedBuilds[x];
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]
log += "* ${entry.msg} by ${entry.author} \n"
}
}
}
return log;
}Additionally, you may try out "Changes Since Last Success Plugin":
https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin
But it will not work together with pipeline, this is a separate approach.
Code Snippets
node('my_kubernetes_pod') {
passedBuilds = []
lastSuccessfulBuild(passedBuilds, currentBuild);
def changeLog = getChangeLog(passedBuilds)
echo "changeLog ${changeLog}"
}
def lastSuccessfulBuild(passedBuilds, build) {
if ((build != null) && (build.result != 'SUCCESS')) {
passedBuilds.add(build)
lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
}
}
@NonCPS
def getChangeLog(passedBuilds) {
def log = ""
for (int x = 0; x < passedBuilds.size(); x++) {
def currentBuild = passedBuilds[x];
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]
log += "* ${entry.msg} by ${entry.author} \n"
}
}
}
return log;
}Context
StackExchange DevOps Q#2310, answer score: 12
Revisions (0)
No revisions yet.