自上次在jenkins管道中成功构建以来,如何获得更改? [英] How to get the changes since the last successful build in jenkins pipeline?
本文介绍了自上次在jenkins管道中成功构建以来,如何获得更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都有Jenkins Pipeline脚本,该脚本可以将自上一次成功构建以来的所有更改填充到变量中?我正在使用git和多分支管道作业.
Anyone have a Jenkins Pipeline script that can stuff all the changes since the previous successful build in a variable? I'm using git and a multibranch pipeline job.
推荐答案
好吧,我设法将某些东西拼凑在一起.我敢肯定,您可以更好地迭代数组,但这是我目前所拥有的:
Well I managed to cobble something together. I'm pretty sure I you can iterate the arrays better but here's what I've got for now:
node('Android') {
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;
}
这篇关于自上次在jenkins管道中成功构建以来,如何获得更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文