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

Declarative: agent inside stage does not do automatic checkout scm

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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'
                  }
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            The reasoning behind automatic checkout only happening at the top level was a conscious decision - and frankly, one I'd still advocate for. But it may make sense to have a per-stage option for "do a fresh checkout of SCM in this stage" - independent of the agent configuration. There've been some other things that have come up that may make sense as part of a stage-level options section.

            Show
            abayer Andrew Bayer added a comment - The reasoning behind automatic checkout only happening at the top level was a conscious decision - and frankly, one I'd still advocate for. But it may make sense to have a per-stage option for "do a fresh checkout of SCM in this stage" - independent of the agent configuration. There've been some other things that have come up that may make sense as part of a stage-level options section.
            Hide
            rtyler R. Tyler Croy added a comment -

            Andrew Bayer, why would you still advocate for it? It's wholly inconsistent behavior between stage-level and pipeline-level agent directives.

            Show
            rtyler R. Tyler Croy added a comment - Andrew Bayer , why would you still advocate for it? It's wholly inconsistent behavior between stage-level and pipeline-level agent directives.
            Hide
            abayer Andrew Bayer added a comment -

            So what I'm leaning towards right now is hooking logic so that the label Declarative agent does always do a checkout (assuming skipDefaultCheckout isn't specified at the top-level, that is) - that'll still avoid doing a redundant checkout when docker or dockerfile are used for an individual stage and reuseNode is specified, since we never actually go through the label Declarative agent then. Implementing now on top of https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/109, which is in the same code (that's JENKINS-41900).

            Show
            abayer Andrew Bayer added a comment - So what I'm leaning towards right now is hooking logic so that the label Declarative agent does always do a checkout (assuming skipDefaultCheckout isn't specified at the top-level, that is) - that'll still avoid doing a redundant checkout when docker or dockerfile are used for an individual stage and reuseNode is specified, since we never actually go through the label Declarative agent then. Implementing now on top of https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/109 , which is in the same code (that's JENKINS-41900 ).
            Hide
            abayer Andrew Bayer added a comment -
            Show
            abayer Andrew Bayer added a comment - Added to the existing related PR https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/109
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            content/doc/book/pipeline/syntax.adoc
            http://jenkins-ci.org/commit/jenkins.io/dde1b744c20b737ea45cbec3db4335710d2d0c84
            Log:
            Uncommenting since JENKINS-41605 landed as well.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: content/doc/book/pipeline/syntax.adoc http://jenkins-ci.org/commit/jenkins.io/dde1b744c20b737ea45cbec3db4335710d2d0c84 Log: Uncommenting since JENKINS-41605 landed as well.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: