一千萬個為什麽

搜索

獲取Jenkins Pipeline上次成功構建後的所有更改日誌



在我的Jenkins管道中,我可以通過這個獲得當前版本的更改日誌。

def changeLogSets = currentBuild.changeSets

自上次成功構建以來,是否有辦法獲取所有更改日誌?

轉載註明原文: 獲取Jenkins Pipeline上次成功構建後的所有更改日誌

一共有 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;
}

Additionally, you may try out "Changes Since Last Success Plugin": https://wiki.jenkins.io/display/JENKINS/Changes+Since+Last+Success+Plugin

但它不會與管道一起工作,這是一種單獨的方法。