Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Jenkins Command to Get the List of Changed Files

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).

like image 361
Men X Avatar asked Jan 14 '19 04:01

Men X


People also ask

What is used to track the changes between builds in Jenkins?

The simplest way to know what has changed on your Jenkins builds! Last Changes is a Jenkin plugin that shows rich VCS diffs between builds. Only Git and Svn based projects are supported.

What is currentBuild in Jenkins?

currentBuild is a global variable that may be used to refer to the currently running build.


1 Answers

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

}
like image 158
TheDukeOfKirkcaldy Avatar answered Oct 17 '22 00:10

TheDukeOfKirkcaldy