Jenkins Pipeline: is it possible to avoid multiple checkout?

I’ve moved a few old Jenkins jobs to new ones using the pipeline feature in order to be able to integrate the Jenkins configuration within the git repositories.
It’s working fine but I’m asking myself if there is a way to reduce the number of checkout that happens while building.


  • What is the fastest way to unstage parts of a new file in git?
  • I accidentally ran `cvs add .git`, what did this do?, how do I recover?
  • Setting remote to use specified port for ssh
  • merge barnch 2 with the latest version of branch 1 in GIT
  • TeamCity build - VCS trigger/Branch specification not working as intended
  • What's the best way to extract a tree from a git repository?
    • I have a Jenkins multibranch job which is related to my git repository
    • I have a Jenkinsfile in my git repository

      node {
        stage 'Checkout'
        checkout scm
        // build project
        stage 'Build'


    When I push to my remote branche BRANCH_1, the multibranch jenkins job is triggered and my understanding is that the following steps happen:

    • the multibranch job makes a git fetch for the branch indexing and triggers the job corresponding to my remote branch: BRANCH_1_job
    • BRANCH_1_job makes a git checkout to retrieve the Jenkinsfile of the triggered branch
    • the Jenkinsfile is executed and makes a checkout scm itself. If I don’t do it, I can not build my project because no source are available.

    So for building my branch, I end up with one git fetch and two git checkout.


    • Do I understand the process correctly? Or did I miss something?
    • Is there a way to reduce the number of git checkout? When I check the official examples, they all make a checkout scm as first step. I would personally think that I don’t have to do it because the jenkins job already had to make a checkout to retrieve the Jenkinsfile (so my sources have to be here somehow).
    • Don’t you think these multiple checkouts can cause bad performance as soon as the git repo contains a big number of refs?

    Thanks you all

  • Cloning a single path of a bare git repository
  • Need GIT workflow suggestion
  • git init, add, commit from a different directory
  • Rebase all branches without switching to them
  • Create a remote branch on GitHub
  • What's the difference between “git symbolic-ref HEAD refs/heads/gh-pages” and “git branch gh-pages”?
  • One Solution collect form web for “Jenkins Pipeline: is it possible to avoid multiple checkout?”

    With plain git Jenkins has to do two checkouts: one to get the Jenkinsfile to know what to execute in the job, and then another checkout of the actual repository content for building purposes.
    Technically Jenkins only needs to load the one single Jenkinsfile from the repo, but git doesn’t allow checkout of a single file. Therefore the double checkout cannot be avoided with plain git using the multibranch plugin.

    If you host git on Bitbucket or GitHub then you avoid the double checkout by using their specific Jenkins plugins instead of the multibranch plugin.

    See the Jenkins plugin site for Bitbucket and GitHub plugins accordingly.

    These plugins use the respective Git provider’s REST API to load the single Jenkins file. So you technically still have a double checkout, but the first one is a simple REST call to download a single file, rather than doing a full native git checkout of the whole repository.

    Git Baby is a git and github fan, let's start git clone.