Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41605

Declarative: agent inside stage does not do automatic checkout scm

XMLWordPrintable

      This pipeline succeeds:

      pipeline {
          agent any
          stages {
              stage ('Build') {
                  steps {
                      sh 'cat Jenkinsfile'
                  }
              }
          }
      }
      

      This pipeline fails:

      pipeline {
          agent any
          stages {
              stage ('Build') {
                  agent any
                  steps {
                      sh 'cat Jenkinsfile'
                  }
              }
          }
      }
      

      The reason this happens is that the agent inside a stage step does not do checkout scm automatically. This is very confusing behavior. Agent initialization should be consistent whether at top or inside a stage.

      I would expect to do something like this to make an agent in a stage not do checkout:

      pipeline {
          agent any
          options {
              skipDefaultCheckout()
          }
          stages {
              stage ('Build') {
                  agent any
                  options {
                      skipDefaultCheckout()
                  }
                  steps {
                      sh 'cat Jenkinsfile'
                  }
              }
          }
      }
      

            abayer Andrew Bayer
            bitwiseman Liam Newman
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: