How to get the changes since the last successful build in jenkins pipeline?

后端 未结 6 545
忘了有多久
忘了有多久 2020-12-09 10:44

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.

6条回答
  •  萌比男神i
    2020-12-09 11:08

    For anyone using Accurev here is an adaptation of andsens answer. andsens answer can't be used because the Accurev plugin doesn't implement getAffectedFiles. Documentation for the AccurevTransaction that extends the ChangeLogSet.Entry class can be found at here.

    import hudson.plugins.accurev.*
    
    def changes = "Changes: \n"
    build = currentBuild
    // Go through the previous builds and get changes until the
    // last successful build is found.
    while (build != null && build.result != 'SUCCESS') {
        changes += "Build ${build.id}:\n"
    
        for (changeLog in build.changeSets) {
            for (AccurevTransaction entry in changeLog.items) {
                changes += "\n    Issue: " + entry.getIssueNum()
                changes += "\n    Change Type: " + entry.getAction()
                changes += "\n    Change Message: " + entry.getMsg()
                changes += "\n    Author: " + entry.getAuthor()
                changes += "\n    Date: " + entry.getDate()
                changes += "\n    Files: "
                for (path in entry.getAffectedPaths()) {
                    changes += "\n        " + path;
                }
                changes += "\n"
            }
        }
        build = build.previousBuild
    }
    echo changes
    writeFile file: "changeLog.txt", text: changes
    

提交回复
热议问题