Declarative: agent dockerfile fails when agent inside stage

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      In a project with a Dockerfile, This pipeline succeeds:

      pipeline {
          agent {
              dockerfile true
          }
          stages {
              stage ('Build') {
                  steps {
                      sh 'echo "hello"'
                  }
              }
          }
      }

      This pipeline fails:

      pipeline {
          agent any
          stages {
              stage ('Build') {
                  agent {
                      dockerfile true
                  }
                  steps {
                      sh 'echo "hello"'
                  }
              }
          }
      }
      

      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.

      The following also works, because of reuseNode true, but dockerfile would never work without that when inside a state (due to JENKINS-41605).

      pipeline {
          agent any
          stages {
              stage ('Build') {
                  agent {
                      dockerfile {
                          reuseNode true
                      }
                  }
                  steps {
                      sh 'echo "hello"'
                  }
              }
          }
      }
      

            Assignee:
            Andrew Bayer
            Reporter:
            Liam Newman
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: