how to get list of all modified files in pipeline jenkins?

jenkins pipeline changelog
jenkins deploy only changed files
jenkins get list of changed files svn
jenkins changeset variable
jenkins pipeline check changeset
jenkins pipeline get commit message
jenkins check git changes
jenkins pipeline get current build log

I'm using multibranch pipeline and i need to get the list of modified files.

i tried

git diff $PREVIOUS_COMMIT $COMMIT

but they have the same SHA.

According to this article at CloudBees, you can access such information inside a pipeline also without white-listing (using Sandbox / script security, compared to my other answer), starting from workflow-support Plugin version 2.2:

def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
    def entries = changeLogSets[i].items
    for (int j = 0; j < entries.length; j++) {
        def entry = entries[j]
        echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
        def files = new ArrayList(entry.affectedFiles)
        for (int k = 0; k < files.size(); k++) {
            def file = files[k]
            echo "  ${file.editType.name} ${file.path}"
        }
    }
}

How to access Changelogs in a Pipeline Job? – CloudBees Support, Pipeline Supporting APIs Plugin 2.2 or above Following is an example of Git for a non-sandboxed build: My function, which creates a string from all the changes (to be used by slackNotify): Using the code in the article only lists the first affected file, and I'm not sure why; shouldn't it iterate through the  I'm trying to list files in the workspace in a Jenkins Pipeline, so that I can use that to produce appropriate parallel tasks. While I could simply use sh ls > files and read that, I want File objects which I can filter further with more complex logic. In fact, Files.listFiles(FileFilter) would be ideal. However, I can't get the list of files

Reference link: https://support.cloudbees.com/hc/en-us/articles/217630098

FYI: Pipeline Supporting APIs Plugin 2.2 or above

You can use currentBuild.changeSets in a sandboxed build as you could see in the following example of Git:

def changeLogSets = currentBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
    def entries = changeLogSets[i].items
    for (int j = 0; j < entries.length; j++) {
        def entry = entries[j]
        echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
        def files = new ArrayList(entry.affectedFiles)
        for (int k = 0; k < files.size(); k++) {
            def file = files[k]
            echo "  ${file.editType.name} ${file.path}"
        }
    }
}

Pipeline Supporting APIs Plugin older than 2.2

You can use currentBuild.rawBuild.changeSets but this is not accessible from the sandbox. Following is an example of Git for a non-sandboxed build:

def changeLogSets = currentBuild.rawBuild.changeSets
for (int i = 0; i < changeLogSets.size(); i++) {
    def entries = changeLogSets[i].items
    for (int j = 0; j < entries.length; j++) {
        def entry = entries[j]
        echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
        def files = new ArrayList(entry.affectedFiles)
        for (int k = 0; k < files.size(); k++) {
            def file = files[k]
            echo "  ${file.editType.name} ${file.path}"
        }
    }
}

Jenkinsfile: build only changed files · GitHub, Jenkinsfile: build only changed files. GitHub Gist: instantly share code, return aci. } def acis = [:]. def aci = { f ->. def file_name = f. acis[f] = {. node ('my-builder'){. 7. Treat all credentials stored in Jenkins as plain text. Treat everyone with access to Jenkins as an admin user, and you will be fine. Once you give someone access, even read-only, to a Jenkins it's game over. All developers on a project should know all secrets anyway. 8. Expect that you will get hacked

You can access such information (after white-listing the API calls) via the currentBuild variable:

currentBuild.rawBuild.getChangeSets().each { cs ->
  cs.getItems().each { item ->
    item.getAffectedFiles().each { f ->
      println f
    }
  }
}

Untested by myself (but makes sense). Source: lsjostro's Gist.

Only modified files in Jenkins, For a custom Jenkins build I needed to know all changed files since the It took me some experimenting to get it working: I installed the Groovy plugin, collects all the paths in these entries - this is the list of all file paths of all  When the Jenkins pipeline is running, you can check its status with the help of Red and Green status symbols. Red means the pipeline has failed, while green indicates success. In this example, we see that the button is green. Hence, the pipeline is successful. Running Jenkins pipeline. Click on Run to run the Jenkins pipeline. It will look something like this:

Jenkins to test only files changed in Git commit, There is no need to waste CPU cycles processing every file for this BOM character, so we only wanted to check for new files. The command to  Run your Pipeline on the development branch. Go back to Jenkins again, log in again if necessary and ensure you’ve accessed Jenkins’s Blue Ocean interface. Click Branches at the top right to access the list of your Pipeline project’s branches. Click the run icon of the development branch of your Pipeline project,

Pipeline as Code, To use Pipeline as Code, projects must contain a file named Jenkinsfile in the complete, consolidate all the changes that have happened since commit one and This trace log of this artifact and a list of all fingerprinted artifacts in a build will  An environment directive used in the top-level pipeline block will apply to all steps within the Pipeline. 2: An environment directive defined within a stage will only apply the given environment variables to steps within the stage.

Using a Jenkinsfile, As discussed in the Defining a Pipeline in SCM, a Jenkinsfile is a text file that Not all Pipelines will have these same three stages, but it is a good starting point to define The full list of environment variables accessible from within Jenkins Pipeline is In the Test example above, the sh step was modified to never return a  At the very least if the list was empty, or maybe a simple message was displayed saying changed files can not be shown because job uses a shallow clone. For users that link their repository browsers to their Jenkins jobs can still refer back to the source repo to get a correct list of changes as a fallback anyway.

Comments
  • Possible duplicate of How to get list of changed files since last build in Jenkins/Hudson
  • @Mahmoud this is not necessary a duplicate. There are additional possibilities with Jenkins Pipelines.
  • @Mahmoud, no this is not a duplicate. I already check the proposed solutions on the link you provide.
  • You're right, sorry for the bad intervention
  • thank you for your reply. This solution show me also the files changed on my librairy? how can i avoid this?
  • There's some option to the library step to disable the changelog.
  • library(identifier: 'mylib', changelog: false)
  • For me, this solution does not work. It gives me a lot of changes even I changed one file.
  • Then please ask a new question with sufficient detail.