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

Additional build args not taken into account for image name for pipeline Dockerfile

    XMLWordPrintable

Details

    Description

      In https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/69e6f4af23665b6aee29fb050056463149122a82/pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineFromDockerfileScript.groovy#L68

      the hash for the the image to be built is computed, however this not properly take into account that we may use the same Dockerfile just with different build arguments to change the resulting image.

      // Work-around for Jenkins not killing/removing older queued jobs
      for (int i = 0; i < (BUILD_NUMBER as int); i++) {milestone()}
      
      // What follows is the actual pipeline that we want Jenkins to go and build, along with all of the stages
      
      pipeline {
          options {
              timeout(time: 1, unit: 'HOURS')
                  timestamps()
          }
      
          agent none;
      
          stages {
              stage("Unit Testing") {
                  parallel {
                      stage("Python 3.7") {
                          agent {
                              dockerfile {
                                  filename 'Dockerfile.jenkins'
                                  additionalBuildArgs '--build-arg TAG=3.7'
                                  label 'docker'
                              }
                          }
                          steps {
                              sh 'tox -e py37'
                              stash name: 'py37_coverage', includes: '.coverage.py37'
                          }
                          post {
                              always {
                                  junit 'junit.xml'
                              }
                          }
                      }
                      stage("Python 3.6") {
                          agent {
                              dockerfile {
                                  filename 'Dockerfile.jenkins'
                                  additionalBuildArgs '--build-arg TAG=3.6'
                                  label 'docker'
                              }
                          }
                          steps {
                              sh 'tox -e py36'
                              stash name: 'py36_coverage', includes: '.coverage.py36'
                          }
                          post {
                              always {
                                  junit 'junit.xml'
                              }
                          }
                      }
                  }
              }
          }
      }
      

      Will both build an image that is going to be tagged with the exact same sha hash, which means that either one of them is going to end up executing inside the wrong docker container.

      18:57:26 -0600  + docker build -t 1d1e61023e37853427ab75fc92cac3ab6e0d4c58 --build-arg TAG=3.7 -f Dockerfile.jenkins .
      18:57:26 -0600  + docker build -t 1d1e61023e37853427ab75fc92cac3ab6e0d4c58 --build-arg TAG=3.6 -f Dockerfile.jenkins .
      

      Attachments

        Activity

          xistence Bert JW Regeer created issue -
          benkeith Ben Keith made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          benkeith Ben Keith made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Fixed but Unreleased [ 10203 ]

          People

            Unassigned Unassigned
            xistence Bert JW Regeer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: