<p>You can also as an alternative set the option to <code>false</code> for the stage where you want to check out the git:</p>

<pre><code>pipeline {
  agent none
  options { skipDefaultCheckout(true) }
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      options { skipDefaultCheckout(false) }
      steps {
        echo 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test') {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        echo 'test-the-app'
      }
    }
  }
}
</code></pre>

CC BY-SA 4.0
2019-01-24T08:47:05.590Z
2019-01-24T08:47:05.590Z
Even André Fiskvik
<p>You can use the <code>checkout scm</code> step whenever you need the source:</p>

<pre><code>pipeline {
  agent none
  options { skipDefaultCheckout() }
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      steps {
        checkout scm
        echo 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test') {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        echo 'test-the-app'
      }
    }
  }
}
</code></pre>

CC BY-SA 3.0
2017-09-03T06:13:53.890Z
2017-09-03T06:13:53.890Z
burnettk
<p>I have a Jenkins pipeline in which I build in one stage and test in another. I'd like them to be different machines since they have different capabilities. I have something like the following so far:</p>

<pre><code>pipeline {
  agent none
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      steps {
        sh 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test’) {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        sh 'test-the-app'
      }
    }
  }
}
</code></pre>

<p>The problem I have is that since it runs on two different nodes, by default it checks out the repository on both nodes. I'd like for it to not do that because it's not needed. So I added the following option:</p>

<pre><code>options { skipDefaultCheckout() }
</code></pre>

<p>But now no repositories are checked out, causing the build to not work. How do I, after specifying <code>skipDefaultCheckout</code>, manually tell the pipeline to checkout the repository in stages which I specify?</p>

CC BY-SA 3.0
2017-08-09T03:29:19.177Z
Can you show where exactly in the config did you add the option? (maybe add it commented out?)
Dan Cornilescu
<jenkins><jenkins-pipeline>
How to check out GitHub repo after specifying skipDefaultCheckout in Jenkins declarative pipeline?
Roxy
# How to check out GitHub repo after specifying skipDefaultCheckout in Jenkins declarative pipeline?

(Asked by: username_0 on 2017-08-08)

I have a Jenkins pipeline in which I build in one stage and test in another. I'd like them to be different machines since they have different capabilities. I have something like the following so far:
pipeline {
  agent none
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      steps {
        sh 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test’) {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        sh 'test-the-app'
      }
    }
  }
}

The problem I have is that since it runs on two different nodes, by default it checks out the repository on both nodes. I'd like for it to not do that because it's not needed. So I added the following option:
options { skipDefaultCheckout() }

But now no repositories are checked out, causing the build to not work. How do I, after specifying skipDefaultCheckout, manually tell the pipeline to checkout the repository in stages which I specify?

**Tags:** jenkins, jenkins-pipeline

> **Comments:**
> **username_1**: Can you show where exactly in the config did you add the option? (maybe add it commented out?)  

---

## 2 answers

### Answer by username_3 on 2017-09-03. Score: 9

You can use the checkout scm step whenever you need the source:
pipeline {
  agent none
  options { skipDefaultCheckout() }
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      steps {
        checkout scm
        echo 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test') {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        echo 'test-the-app'
      }
    }
  }
}


---

### Answer by username_2 on 2019-01-24. Score: 2

You can also as an alternative set the option to false for the stage where you want to check out the git:
pipeline {
  agent none
  options { skipDefaultCheckout(true) }
  stages {
    stage('Build') {
      agent { node { label 'builder' } }
      options { skipDefaultCheckout(false) }
      steps {
        echo 'build-the-app'
        stash(name: 'app', includes: 'outputs')
      }
    }
    stage('Test') {
      agent { node { label 'tester' } }
      steps {
        unstash 'app'
        echo 'test-the-app'
      }
    }
  }
}


---

