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

Declarative: agent inside stage does not do automatic checkout scm

    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

            bitwiseman Liam Newman created issue -
            bitwiseman Liam Newman made changes -
            Field Original Value New Value
            Description This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        steps {
                            sh 'cat Jenkinsfile'
                        }
                    }
                }
            }
            {code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent any
                        steps {
                            sh 'cat Jenkinsfile'
                        }
                    }
                }
            }
            {code}

            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.
            This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        steps {
                            sh 'cat Jenkinsfile'
                        }
                    }
                }
            }
            {code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent any
                        steps {
                            sh 'cat Jenkinsfile'
                        }
                    }
                }
            }
            {code}

            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:
            {code:language=groovy}
            pipeline {
                agent any
                options {
                    skipDefaultCheckout()
                }
                stages {
                    stage ('Build') {
                        agent any
                        options {
                            skipDefaultCheckout()
                        }
                        steps {
                            sh 'cat Jenkinsfile'
                        }
                    }
                }
            }
            {code}
            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.
            bitwiseman Liam Newman made changes -
            Link This issue relates to JENKINS-41607 [ JENKINS-41607 ]
            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.
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            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 ).
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            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
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #109 (Web Link)" [ 15452 ]
            abayer Andrew Bayer made changes -
            Link This issue is duplicated by JENKINS-41607 [ JENKINS-41607 ]
            abayer Andrew Bayer made changes -
            Status In Review [ 10005 ] Resolved [ 5 ]
            Resolution Fixed [ 1 ]
            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.
            cloudbees CloudBees Inc. made changes -
            Remote Link This issue links to "CloudBees Internal OSS-1996 (Web Link)" [ 18472 ]
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
            bitwiseman Liam Newman made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

              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: