Which Jenkins Command to Get the List of Changed Files

自古美人都是妖i 提交于 2019-12-23 01:05:09

问题


In a Jenkins build I see a list of changed files:

So which command Jenkins uses to get this list (I am using git for repository version control).


回答1:


You can use the changeSets property of the currentBuild global variable to get information relating to the detected changes of the current build.

e.g.

// returns a list of changed files
@NonCPS
String getChangedFilesList() {

    changedFiles = []
    for (changeLogSet in currentBuild.changeSets) { 
        for (entry in changeLogSet.getItems()) { // for each commit in the detected changes
            for (file in entry.getAffectedFiles()) {
                changedFiles.add(file.getPath()) // add changed file to list
            }
        }
    }

    return changedFiles

}



回答2:


Possibly one of the two possible commands listed in "How to list all the files in a commit?":

git diff-tree --no-commit-id --name-only -r <commit-ish>

Note that the Jenkins Git plugin does expose that commit as an environment variable: GIT_COMMIT



来源:https://stackoverflow.com/questions/54175878/which-jenkins-command-to-get-the-list-of-changed-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!