def changeLogSets = currentBuild.changeSets
有没有办法获取自上次成功构建以来的所有变更日志?
#1 楼
您可以尝试执行以下操作: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;
}
另外,您可以尝试“自上次成功插件以来的变化”:
https://wiki.jenkins。 io / display / JENKINS / Changes + Since + Last + Success + Plugin
但它不能与管道一起使用,这是一种单独的方法。
#2 楼
我发现可能对您有帮助。这样,您可以获取使用Jenkins构建的任何项目的最新成功构建更改日志文件。$DirectoryA = "D:\Jenkins\jobs\projectName\builds" ####Jenkind directory
$firstfolder = Get-ChildItem -Path $DirectoryA | Where-Object {$_.PSIsContainer} | Sort-Object LastWriteTime -Descending | Select-Object -First 1
$DirectoryB = $DirectoryA + "\" + $firstfolder
$sVnLoGfIle = $DirectoryB + "\" + "changelog.xml"
write-host $sVnLoGfIle
评论
看来此解决方案提供了最后成功构建的更改日志。我真正要寻找的是自上次成功构建以来的变更日志(上次未成功构建)。但是您的回答肯定有帮助。 Build.getpreviousebuuld()和递归是我所错过的。非常感谢您的回答。
–蜜蜂
17-10-14在5:58
随时欢迎 ;-)
–user54
17-10-14在6:33
我怀疑如果您要进行大量构建,则递归解决方案可能会遇到堆栈用尽的问题。不过,切换到迭代过程并不难。
–酒
17-10-28在18:46