哪个Jenkins命令获取更改文件列表

时间:2019-01-14 04:41:33

标签: git jenkins jenkins-cli

在Jenkins构建中,我看到了已更改文件的列表:

enter image description here

因此,詹金斯使用哪个命令来获取此列表(我正在使用git进行存储库版本控制)。

2 个答案:

答案 0 :(得分:1)

您可以使用 currentBuild 全局变量的changeSets属性来获取与检测到的当前版本更改有关的信息。

例如

// 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

}

答案 1 :(得分:0)

How to list all the files in a commit?”中列出的两个可能的命令之一:

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

请注意,Jenkins Git plugin确实将该提交作为环境变量公开:GIT_COMMIT