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

Declarative: agent dockerfile fails when agent inside stage

    XMLWordPrintable

Details

    Description

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

      Attachments

        Issue Links

          Activity

            abayer Andrew Bayer added a comment -

            This is effectively a symptom of JENKINS-41605, so closing this.

            abayer Andrew Bayer added a comment - This is effectively a symptom of JENKINS-41605 , so closing this.
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

            People

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

              Dates

                Created:
                Updated:
                Resolved: