Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-24T08:47:05.590Z
Answers: 2019-01-24T08:47:05.590Z
Answers: Even André Fiskvik
Answers: <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>
  
Answers: CC BY-SA 3.0
Answers: 2017-09-03T06:13:53.890Z
Answers: 2017-09-03T06:13:53.890Z
Answers: burnettk
Body: <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>
  
Comments: CC BY-SA 3.0
Comments: 2017-08-09T03:29:19.177Z
Comments: Can you show where exactly in the config did you add the option? (maybe add it commented out?)
Comments: Dan Cornilescu
Tags: <jenkins><jenkins-pipeline>
Title: How to check out GitHub repo after specifying skipDefaultCheckout in Jenkins declarative pipeline?
UserDisplayName: Roxy
ThreadText: # 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'
        }
      }
    }
  }
  
  ```
  
  
  ---
  
  