[英]How to get the changes since the last successful build in jenkins pipeline?
[英]In a Jenkins pipeline, how can I get the files that changed between the current build and last successful build?
我正在嘗試擴展自上次在 jenkins 管道中成功構建以來如何獲得更改的帖子? . 如何獲取更改集中當前構建和上次成功構建之間更改的文件而不是日志? 我不想要每個文件中的實際更改,而只想要更改的文件列表。 我想要相當於做一個
$ git diff commit#1 commit#2 --name-only
注意我修改了這個函數以至少獲取當前構建和上次成功構建之間的更改集。 在我的例子中,我將currentBuild
狀態設置為SUCCESS
所以它被算作passedBuild
,因此檢查passedBuilds.size() < 2
。
////////////////////////////////////////////////////////////////////
// Code to get change sets between the current and last successful
// build
////////////////////////////////////////////////////////////////////
def lastSuccessfulBuild(passedBuilds, build) {
if (build != null) {
if (build.result != 'SUCCESS' || passedBuilds.size() < 2) {
passedBuilds.add(build)
lastSuccessfulBuild(passedBuilds, build.getPreviousBuild())
}
}
}
提前致謝。
這可能不是您所需要的,下面的方法返回觸發當前構建的提交中修改的文件集。 它將在重新運行時返回空列表。
def getChangedFiles(passedBuilds) {
def files = [] as Set // as Set assumes uniqueness
passedBuilds.each {
def changeLogSets = it.rawBuild.changeSets
changeLogSets.each {
it.items.each {
it.affectedFiles.each {
files.add(it.path)
}
}
}
}
echo "Found changes in files: ${files}"
return files.toSorted()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.