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

Latest docker image is not pulled when used within stage

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When a docker image is used as an agent at the pipeline level, `image.pull()` is called automatically to check for a newer version. E.g.:

      pipeline {
        agent { docker 'microsoft/dotnet' }
        stages {
          stage('x') {
            steps {
              sh '...'
            }
          }
        }
      }
      

      However, when a docker image is used as an agent at the stage level, `image.pull()` is never called, so potentially old images are used instead.E.g.:

      pipeline {
        agent none
        stages {
          stage('x') {
            agent { docker 'microsoft/dotnet' }
            steps {
              sh '...'
            }
          }
        }
      }
      

      Is it possible to automatically call `image.pull()` as well, or at least provide an option flag to state you want this behaviour?

      I believe the code that affects this is: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/824b3b7a96cc9d4fc6fc636caccaed3d39343cfd/pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineScript.groovy#L42

        Attachments

          Issue Links

            Activity

            Hide
            scottles Scott Hilleard added a comment -

            Because we need to mount the workspace inside the container and you can not mount a volume with the dockerfile agent.

             

            Show
            scottles Scott Hilleard added a comment - Because we need to mount the workspace inside the container and you can not mount a volume with the dockerfile agent.  
            Hide
            chris5287 Chris Stylianou added a comment -

            Sorry missed your args but the following should work:

            agent {
              dockerfile {
                dir 'docker/web_base'
                args '-v $WORKSPACE:/var/www'
              }
            }
            

            See: https://stackoverflow.com/questions/44805076/setting-build-args-for-dockerfile-agent-using-a-jenkins-declarative-pipeline#answer-46359650

            Show
            chris5287 Chris Stylianou added a comment - Sorry missed your args but the following should work: agent { dockerfile { dir 'docker/web_base' args '-v $WORKSPACE:/ var /www' } } See: https://stackoverflow.com/questions/44805076/setting-build-args-for-dockerfile-agent-using-a-jenkins-declarative-pipeline#answer-46359650
            Hide
            scottles Scott Hilleard added a comment -

            If that works, it is not presently documented as a feature and probably should be! I will give that a try (though I still think the option to pull an image should be an option of the agent, even if it is the default). Thanks!

             

            Show
            scottles Scott Hilleard added a comment - If that works, it is not presently documented as a feature and probably should be! I will give that a try (though I still think the option to pull an image should be an option of the agent, even if it is the default). Thanks!  
            Hide
            scottles Scott Hilleard added a comment -

            Chris, just to confirm yes the "args" parameter does indeed work with the Dockerfile agent and we can map in volumes. That really should be in the dockerfile agent documentation as it is a very useful feature! Thank you for your help!

             

            Show
            scottles Scott Hilleard added a comment - Chris, just to confirm yes the "args" parameter does indeed work with the Dockerfile agent and we can map in volumes. That really should be in the dockerfile agent documentation as it is a very useful feature! Thank you for your help!  
            Hide
            chris5287 Chris Stylianou added a comment -

            Scott Hilleard glad I was able to help!

            I suggest you raise new tickets to individually track adding an optional auto-pull for agents/updating the docker documentation

            Show
            chris5287 Chris Stylianou added a comment - Scott Hilleard  glad I was able to help! I suggest you raise new tickets to individually track adding an optional auto-pull for agents/updating the docker documentation

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                chris5287 Chris Stylianou
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: