Is there some way to get a list of changed files in Pull request?

Hi.

I’ve configured a multi-branch project with cloudbees-bitbucket-branch-source plugin in jenkins. When Pull Request(PR) is created it triggers build configuratin from Jenkinsfile in project code.
The problem: there is no way to get a list of changed files for all commits in PR
When I try to use this command:

git diff --name-only PR-BRANCH develop

it returns error:

fatal: ambiguous argument ‘PR-BRANCH’: unknown revision or path not in the working tree

Because “checkout scm” pipeline step doens’t fetch all needed branches (only last commit)

You can call checkout scm yourself and extend the definition of the refspec to include all the branches in the repository.

An example might look like this:

pipeline {
    options {
        skipDefaultCheckout()
    }
    stages {
        stage("root build.xml") {
            steps {
                // Initial checkout to provide only build.xml at root of workspace
                checkout([$class: 'GitSCM',
                          branches: [
                              [name: 'JENKINS-60617']
                          ],
                          extensions: [
                              [$class: 'CloneOption', depth: 1, honorRefspec: true, noTags: true, reference: '/var/lib/git/mwaite/bugs/jenkins-bugs.git', shallow: true],
                              [$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'build.xml']]], // exactly one file we need, nothing else
                          ],
                          userRemoteConfigs: [
                              [refspec: '+refs/heads/JENKINS-60617:refs/remotes/origin/JENKINS-60617', url: scm.userRemoteConfigs[0].url]
                          ]
                         ]
                )
            }
        }
    }
}

That example could be improved by replacing the reference to $class: GitSCM with the symbol scmGit, but you can do that replacement from the Pipeline Syntax Snippet Generator to get the best syntax