Which Jenkins Command to Get the List of Changed Files

Men X picture Men X · Jan 14, 2019 · Viewed 13.3k times · Source

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

enter image description here

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

Answer

TheDukeOfKirkcaldy picture TheDukeOfKirkcaldy · Jan 14, 2019

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

}