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

Declarative: agent dockerfile fails when agent inside stage

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

            abayer Andrew Bayer
            bitwiseman Liam Newman
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: