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

Declarative: agent dockerfile fails when agent inside stage

    Details

    • Similar Issues:

      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

            bitwiseman Liam Newman created issue -
            bitwiseman Liam Newman made changes -
            Field Original Value New Value
            Link This issue relates to JENKINS-41605 [ JENKINS-41605 ]
            bitwiseman Liam Newman made changes -
            Description In a project with a {{Dockerfile}}, This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent {
                    dockerfile true
                }
                stages {
                    stage ('Build') {
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }{code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent none
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile true
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {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.
            abayer Andrew Bayer made changes -
            Summary Declarative: agent dockerfile fails when agent inside stage Declarative: agent dockerfile fails when agent inside stage with top-level agent none
            bitwiseman Liam Newman made changes -
            Summary Declarative: agent dockerfile fails when agent inside stage with top-level agent none Declarative: agent dockerfile fails when agent inside stage
            bitwiseman Liam Newman made changes -
            Description In a project with a {{Dockerfile}}, This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent {
                    dockerfile true
                }
                stages {
                    stage ('Build') {
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }{code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent none
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile true
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {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.
            In a project with a {{Dockerfile}}, This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent {
                    dockerfile true
                }
                stages {
                    stage ('Build') {
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }{code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile true
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {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.
            bitwiseman Liam Newman made changes -
            Description In a project with a {{Dockerfile}}, This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent {
                    dockerfile true
                }
                stages {
                    stage ('Build') {
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }{code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile true
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {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.
            In a project with a {{Dockerfile}}, This pipeline succeeds:

            {code:language=groovy}
            pipeline {
                agent {
                    dockerfile true
                }
                stages {
                    stage ('Build') {
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }{code}

            This pipeline fails:

            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile true
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {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.


            The following also works, because of {{reuseNode true}}, but dockerfile would never work without that when inside a state (due to JENKINS-41605).
            {code:language=groovy}
            pipeline {
                agent any
                stages {
                    stage ('Build') {
                        agent {
                            dockerfile {
                                reuseNode true
                            }
                        }
                        steps {
                            sh 'echo "hello"'
                        }
                    }
                }
            }
            {code}
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Hide
            abayer Andrew Bayer added a comment -

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

            Show
            abayer Andrew Bayer added a comment - This is effectively a symptom of JENKINS-41605 , so closing this.
            abayer Andrew Bayer made changes -
            Link This issue duplicates JENKINS-41605 [ JENKINS-41605 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] Resolved [ 5 ]
            Resolution Duplicate [ 3 ]
            cloudbees CloudBees Inc. made changes -
            Remote Link This issue links to "CloudBees Internal OSS-1995 (Web Link)" [ 18473 ]
            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:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: