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

docker.inside within a withRegistry block seems to use image.id instead of image.imageName()

      I'm trying to execute a maven build inside of my custom container (my.registry.com/build-env:jdk8-maven3):

      node('docker') {
           docker.withRegistry('https://my.registry.com', 'docker-registry-login') {
              def maven = docker.image("my-build-env:jdk8-maven3")
              
              sh "echo ${maven.imageName()} -- ${maven.id}"
              maven.pull()
              maven.inside() {
                  sh "echo Hello"
              }
           }
      }
      

      It goes well until the pull, which uses the imageName (my.registry.com/build-env:jdk8-maven3) but the run command uses id (build-env:jdk8-maven3)

      Abbreviated logs:

      Started by user Radesh Rao
      [Pipeline] Allocate node : Start
      Running on docker in /data/jenkins/workspace/My pipeline
      [Pipeline] node {
      [Pipeline] Set environment variables : Start
      [Pipeline] withEnv {
      [Pipeline] Sets up Docker registry endpoint : Start
      [Pipeline] withDockerRegistry {
      [Pipeline] sh
      [Cloud pipeline] Running shell script
      + echo my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3
      my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3
      [Pipeline] sh
      [Cloud pipeline] Running shell script
      + docker inspect -f . build-env:jdk8-maven3
      
      Error: No such image or container: build-env:jdk8-maven3
      [Pipeline] sh
      [Cloud pipeline] Running shell script
      + docker pull my.registry.com/build-env:jdk8-maven3
      jdk8-maven3: Pulling from build-env
      fdd5d7827f33: Pulling fs layer
      // ....
      // snip
      // ....
      416e801cfa37: Pull complete
      Digest: sha256:cadb8d0e48a2dc98d1c88f633b8ac226d5df00ffeaa66d3522b02dfdd055351b
      Status: Downloaded newer image for my.registry.com/build-env:jdk8-maven3
      [Pipeline] Run build steps inside a Docker container : Start
      $ docker run -t -d -u 995:991 -w "/data/jenkins/workspace/My pipeline" -v "/data/jenkins/workspace/My pipeline:/data/jenkins/workspace/My pipeline:rw" -v "/data/jenkins/workspace/My pipeline@tmp:/data/jenkins/workspace/My pipeline@tmp:rw" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** build-env:jdk8-maven3 cat
      [Pipeline] Run build steps inside a Docker container : End
      [Pipeline] } //withDockerRegistry
      [Pipeline] Sets up Docker registry endpoint : End
      [Pipeline] } //withEnv
      [Pipeline] Set environment variables : End
      [Pipeline] } //node
      [Pipeline] Allocate node : End
      [Pipeline] End of Pipeline
      java.io.IOException: Failed to run image 'build-env:jdk8-maven3'. Error: Unable to find image 'build-env:jdk8-maven3' locally
      docker: Error response from daemon: Authentication is required: Get https://registry-1.docker.io/v2/library/build-env/manifests/jdk8-maven3: unauthorized: incorrect username or password.
      See 'docker run --help'.
      	at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:112)
      	at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:145)
      	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:136)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
      	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
      	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/lib/jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:112)
      	at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/var/lib/jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:63)
      	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/lib/jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:104)
      	at WorkflowScript.run(WorkflowScript:10)
      	at org.jenkinsci.plugins.docker.workflow.Docker.withRegistry(jar:file:/var/lib/jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:38)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
      	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
      	at sun.reflect.GeneratedMethodAccessor518.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:606)
      	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:40)
      	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
      	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:277)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:724)
      Finished: FAILURE
      

          [JENKINS-34276] docker.inside within a withRegistry block seems to use image.id instead of image.imageName()

          Jesse Glick added a comment -

          Proposed patch:

          diff --git a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          index 5842ed5..6a84158 100644
          --- a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          +++ b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          @@ -109,7 +109,7 @@ class Docker implements Serializable {
                               // withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
                               pull()
                           }
          -                docker.script.withDockerContainer(image: id, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
          +                docker.script.withDockerContainer(image: imageName(), args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
                               body()
                           }
                       }
          

          but need to figure out how to reproduce the problem to verify the fix.

          Jesse Glick added a comment - Proposed patch: diff --git a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy index 5842ed5..6a84158 100644 --- a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy +++ b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy @@ -109,7 +109,7 @@ class Docker implements Serializable { // withDockerContainer requires the image to be available locally, since its start phase is not a durable task. pull() } - docker.script.withDockerContainer(image: id, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) { + docker.script.withDockerContainer(image: imageName(), args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) { body() } } but need to figure out how to reproduce the problem to verify the fix.

          Radesh Rao added a comment -

          jglick: I'll try and build this patch and test out the plugin.

          Radesh Rao added a comment - jglick : I'll try and build this patch and test out the plugin.

          Radesh Rao added a comment -

          The test job that I had succeeds with the patch:

          Started by user Radesh Rao
          [Pipeline] Allocate node : Start
          Running on docker in /data/jenkins/workspace/My pipeline
          [Pipeline] node {
          [Pipeline] Set environment variables : Start
          [Pipeline] withEnv {
          [Pipeline] Sets up Docker registry endpoint : Start
          [Pipeline] withDockerRegistry {
          [Pipeline] sh
          [Cloud pipeline] Running shell script
          + echo my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3
          my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3
          [Pipeline] sh
          [Cloud pipeline] Running shell script
          + docker inspect -f . build-env:jdk8-maven3
          
          Error: No such image or container: build-env:jdk8-maven3
          [Pipeline] sh
          [Cloud pipeline] Running shell script
          + docker pull my.registry.com/build-env:jdk8-maven3
          jdk8-maven3: Pulling from build-env
          // ....
          // snip
          // ....
          Status: Image is up to date for my.registry.com/build-env:jdk8-maven3
          [Pipeline] Run build steps inside a Docker container : Start
          $ docker run -t -d -u 995:991 -w "/data/jenkins/workspace/My pipeline" -v "/data/jenkins/workspace/My pipeline:/data/jenkins/workspace/My pipeline:rw" -v "/data/jenkins/workspace/My pipeline@tmp:/data/jenkins/workspace/My pipeline@tmp:rw" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** my.registry.com/build-env:jdk8-maven3 cat
          [Pipeline] withDockerContainer {
          [Pipeline] sh
          [Cloud pipeline] Running shell script
          + echo Hello
          Hello
          [Pipeline] } //withDockerContainer
          $ docker stop a9bf6ced0bceb9731144db9d639ae702587238d67ad5af55107dec5e5ad54333
          $ docker rm -f a9bf6ced0bceb9731144db9d639ae702587238d67ad5af55107dec5e5ad54333
          [Pipeline] Run build steps inside a Docker container : End
          [Pipeline] } //withDockerRegistry
          [Pipeline] Sets up Docker registry endpoint : End
          [Pipeline] } //withEnv
          [Pipeline] Set environment variables : End
          [Pipeline] } //node
          [Pipeline] Allocate node : End
          [Pipeline] End of Pipeline
          Finished: SUCCESS
          

          Radesh Rao added a comment - The test job that I had succeeds with the patch: Started by user Radesh Rao [Pipeline] Allocate node : Start Running on docker in /data/jenkins/workspace/My pipeline [Pipeline] node { [Pipeline] Set environment variables : Start [Pipeline] withEnv { [Pipeline] Sets up Docker registry endpoint : Start [Pipeline] withDockerRegistry { [Pipeline] sh [Cloud pipeline] Running shell script + echo my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3 my.registry.com/build-env:jdk8-maven3 -- build-env:jdk8-maven3 [Pipeline] sh [Cloud pipeline] Running shell script + docker inspect -f . build-env:jdk8-maven3 Error: No such image or container: build-env:jdk8-maven3 [Pipeline] sh [Cloud pipeline] Running shell script + docker pull my.registry.com/build-env:jdk8-maven3 jdk8-maven3: Pulling from build-env // .... // snip // .... Status: Image is up to date for my.registry.com/build-env:jdk8-maven3 [Pipeline] Run build steps inside a Docker container : Start $ docker run -t -d -u 995:991 -w "/data/jenkins/workspace/My pipeline" -v "/data/jenkins/workspace/My pipeline:/data/jenkins/workspace/My pipeline:rw" -v "/data/jenkins/workspace/My pipeline@tmp:/data/jenkins/workspace/My pipeline@tmp:rw" -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** my.registry.com/build-env:jdk8-maven3 cat [Pipeline] withDockerContainer { [Pipeline] sh [Cloud pipeline] Running shell script + echo Hello Hello [Pipeline] } //withDockerContainer $ docker stop a9bf6ced0bceb9731144db9d639ae702587238d67ad5af55107dec5e5ad54333 $ docker rm -f a9bf6ced0bceb9731144db9d639ae702587238d67ad5af55107dec5e5ad54333 [Pipeline] Run build steps inside a Docker container : End [Pipeline] } //withDockerRegistry [Pipeline] Sets up Docker registry endpoint : End [Pipeline] } //withEnv [Pipeline] Set environment variables : End [Pipeline] } //node [Pipeline] Allocate node : End [Pipeline] End of Pipeline Finished: SUCCESS

          Art V added a comment -

          Same type of issue when using withRegistry and image.run() command. It uses the ID and not the imageName() so fails to find the image from the private registry. Should be same type of fix as this.

          Art V added a comment - Same type of issue when using withRegistry and image.run() command. It uses the ID and not the imageName() so fails to find the image from the private registry. Should be same type of fix as this.

          Jacob Blain Christen added a comment - - edited

          Steps to Reproduce for jglick:

          1. Build image example/jenkins-34276:latest private repository repo.example.com:5000
          2. Verify you can pull this image from your Jenkins slave, e.g.:
            docker pull repo.example.com:5000/example/jenkins-34276:latest
            
          3. Attempt to access image with the below pipeline snippet (assumes credentials anonymous exist are allowed to pull from the private repo):
            node ('build && docker') {
                docker.withRegistry('https://repo.example.com:5000', 'anonymous') {
                    def exampleImg = docker.image('example/jenkins-34276)
                    exampleImg.pull() // make sure the image is up-to-date
                    exampleImg.inside {
                        sh 'env | sort'
                    }
                }
            }
            
          4. Witness failure as below:
            Started by user Jacob Blain Christen
            [Pipeline] node
            Running on build-507941e0b4db in /var/lib/jenkins/workspace/JCHRISTEN/docker-inside
            [Pipeline] {
            [Pipeline] withEnv
            [Pipeline] {
            [Pipeline] withDockerRegistry
            [Pipeline] {
            [Pipeline] sh
            [docker-inside] Running shell script
            + docker pull repo.example.com:5000/example/jenkins-34276
            Using default tag: latest
            latest: Pulling from example/jenkins-34276
            6599cadaf950: Already exists
            23eda618d451: Already exists
            f0be3084efe9: Already exists
            52de432f084b: Already exists
            a3ed95caeb02: Already exists
            79ea8cd5fef8: Already exists
            b5b96651da0d: Pulling fs layer
            945ed45a59ec: Pulling fs layer
            f720300846de: Pulling fs layer
            80e10de1adee: Pulling fs layer
            80e10de1adee: Waiting
            f720300846de: Verifying Checksum
            f720300846de: Download complete
            80e10de1adee: Verifying Checksum
            80e10de1adee: Download complete
            b5b96651da0d: Verifying Checksum
            b5b96651da0d: Download complete
            945ed45a59ec: Verifying Checksum
            945ed45a59ec: Download complete
            b5b96651da0d: Pull complete
            b5b96651da0d: Pull complete
            945ed45a59ec: Pull complete
            945ed45a59ec: Pull complete
            f720300846de: Pull complete
            f720300846de: Pull complete
            80e10de1adee: Pull complete
            80e10de1adee: Pull complete
            Digest: sha256:c526a65b8bd1a7e68a7376a1b53e0880d6955f9a7aa29d8df56b5a8fac9b8537
            Status: Downloaded newer image for repo.example.com:5000/example/jenkins-34276:latest
            [Pipeline] sh
            [docker-inside] Running shell script
            + docker inspect -f . example/jenkins-34276
            
            Error: No such image or container: example/jenkins-34276
            [Pipeline] sh
            [docker-inside] Running shell script
            + docker pull repo.example.com:5000/example/jenkins-34276
            Using default tag: latest
            latest: Pulling from example/jenkins-34276
            Digest: sha256:c526a65b8bd1a7e68a7376a1b53e0880d6955f9a7aa29d8df56b5a8fac9b8537
            Status: Image is up to date for repo.example.com:5000/example/jenkins-34276:latest
            [Pipeline] withDockerContainer
            $ docker run -t -d -u 1000:1000 -w /var/lib/jenkins/workspace/JCHRISTEN/docker-inside -v /var/lib/jenkins/workspace/JCHRISTEN/docker-inside:/var/lib/jenkins/workspace/JCHRISTEN/docker-inside:rw -v /var/lib/jenkins/workspace/JCHRISTEN/docker-inside@tmp:/var/lib/jenkins/workspace/JCHRISTEN/docker-inside@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** example/jenkins-34276 cat
            [Pipeline] // withDockerContainer
            [Pipeline] }
            [Pipeline] // withDockerRegistry
            [Pipeline] }
            [Pipeline] // withEnv
            [Pipeline] }
            [Pipeline] // node
            [Pipeline] End of Pipeline
            java.io.IOException: Failed to run image 'example/jenkins-34276'. Error: Unable to find image 'example/jenkins-34276:latest' locally
            Pulling repository docker.io/example/jenkins-34276
            docker: Error: image example/jenkins-34276 not found.
            See 'docker run --help'.
            	at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:112)
            	at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:145)
            	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:137)
            	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
            	at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
            	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
            	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
            	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
            	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103)
            	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149)
            	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146)
            	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15)
            	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:112)
            	at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:63)
            	at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:104)
            	at WorkflowScript.run(WorkflowScript:14)
            	at org.jenkinsci.plugins.docker.workflow.Docker.withRegistry(jar:file:/var/jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:38)
            	at ___cps.transform___(Native Method)
            	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
            	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
            	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79)
            	at sun.reflect.GeneratedMethodAccessor709.invoke(Unknown Source)
            	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            	at java.lang.reflect.Method.invoke(Method.java:498)
            	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
            	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:40)
            	at com.cloudbees.groovy.cps.Next.step(Next.java:58)
            	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
            	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
            	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
            	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:276)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:78)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:185)
            	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:183)
            	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
            	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
            	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
            	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
            	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            	at java.lang.Thread.run(Thread.java:745)
            Finished: FAILURE
            

          Current work-around

          node ('build && docker') {
              docker.withRegistry('https://repo.example.com:5000', 'anonymous') {
                  def exampleImg = docker.image('example/jenkins-34276)
                  exampleImg.pull() // make sure the image is up-to-date
                  docker.image(exampleImg.imageName()).inside {
                      sh 'env | sort'
                  }
              }
          }
          

          Jacob Blain Christen added a comment - - edited Steps to Reproduce for jglick : Build image example/jenkins-34276:latest private repository repo.example.com:5000 Verify you can pull this image from your Jenkins slave, e.g.: docker pull repo.example.com:5000/example/jenkins-34276:latest Attempt to access image with the below pipeline snippet (assumes credentials anonymous exist are allowed to pull from the private repo): node ( 'build && docker' ) { docker.withRegistry( 'https: //repo.example.com:5000' , 'anonymous' ) { def exampleImg = docker.image('example/jenkins-34276) exampleImg.pull() // make sure the image is up-to-date exampleImg.inside { sh 'env | sort' } } } Witness failure as below: Started by user Jacob Blain Christen [Pipeline] node Running on build-507941e0b4db in / var /lib/jenkins/workspace/JCHRISTEN/docker-inside [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] withDockerRegistry [Pipeline] { [Pipeline] sh [docker-inside] Running shell script + docker pull repo.example.com:5000/example/jenkins-34276 Using default tag: latest latest: Pulling from example/jenkins-34276 6599cadaf950: Already exists 23eda618d451: Already exists f0be3084efe9: Already exists 52de432f084b: Already exists a3ed95caeb02: Already exists 79ea8cd5fef8: Already exists b5b96651da0d: Pulling fs layer 945ed45a59ec: Pulling fs layer f720300846de: Pulling fs layer 80e10de1adee: Pulling fs layer 80e10de1adee: Waiting f720300846de: Verifying Checksum f720300846de: Download complete 80e10de1adee: Verifying Checksum 80e10de1adee: Download complete b5b96651da0d: Verifying Checksum b5b96651da0d: Download complete 945ed45a59ec: Verifying Checksum 945ed45a59ec: Download complete b5b96651da0d: Pull complete b5b96651da0d: Pull complete 945ed45a59ec: Pull complete 945ed45a59ec: Pull complete f720300846de: Pull complete f720300846de: Pull complete 80e10de1adee: Pull complete 80e10de1adee: Pull complete Digest: sha256:c526a65b8bd1a7e68a7376a1b53e0880d6955f9a7aa29d8df56b5a8fac9b8537 Status: Downloaded newer image for repo.example.com:5000/example/jenkins-34276:latest [Pipeline] sh [docker-inside] Running shell script + docker inspect -f . example/jenkins-34276 Error: No such image or container: example/jenkins-34276 [Pipeline] sh [docker-inside] Running shell script + docker pull repo.example.com:5000/example/jenkins-34276 Using default tag: latest latest: Pulling from example/jenkins-34276 Digest: sha256:c526a65b8bd1a7e68a7376a1b53e0880d6955f9a7aa29d8df56b5a8fac9b8537 Status: Image is up to date for repo.example.com:5000/example/jenkins-34276:latest [Pipeline] withDockerContainer $ docker run -t -d -u 1000:1000 -w / var /lib/jenkins/workspace/JCHRISTEN/docker-inside -v / var /lib/jenkins/workspace/JCHRISTEN/docker-inside:/ var /lib/jenkins/workspace/JCHRISTEN/docker-inside:rw -v / var /lib/jenkins/workspace/JCHRISTEN/docker-inside@tmp:/ var /lib/jenkins/workspace/JCHRISTEN/docker-inside@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** example/jenkins-34276 cat [Pipeline] // withDockerContainer [Pipeline] } [Pipeline] // withDockerRegistry [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.io.IOException: Failed to run image 'example/jenkins-34276' . Error: Unable to find image 'example/jenkins-34276:latest' locally Pulling repository docker.io/example/jenkins-34276 docker: Error: image example/jenkins-34276 not found. See 'docker run --help' . at org.jenkinsci.plugins.docker.workflow.client.DockerClient.run(DockerClient.java:112) at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:145) at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:137) at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113) at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151) at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:21) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:115) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:103) at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:149) at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:146) at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:15) at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/ var /jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:112) at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/ var /jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:63) at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/ var /jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:104) at WorkflowScript.run(WorkflowScript:14) at org.jenkinsci.plugins.docker.workflow.Docker.withRegistry(jar:file:/ var /jenkins_home/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:38) at ___cps.transform___(Native Method) at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106) at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:79) at sun.reflect.GeneratedMethodAccessor709.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72) at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:40) at com.cloudbees.groovy.cps.Next.step(Next.java:58) at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30) at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108) at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30) at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:276) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:78) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:185) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:183) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang. Thread .run( Thread .java:745) Finished: FAILURE Current work-around node ( 'build && docker' ) { docker.withRegistry( 'https: //repo.example.com:5000' , 'anonymous' ) { def exampleImg = docker.image('example/jenkins-34276) exampleImg.pull() // make sure the image is up-to-date docker.image(exampleImg.imageName()).inside { sh 'env | sort' } } }

          Richard Lee added a comment - - edited

          Same problem. The

          myImage.pull()
          docker.image(myImage.imageName()).inside()

          workaround for

          myImage.inside()

          seems to get around the bug, tho.

          Richard Lee added a comment - - edited Same problem. The myImage.pull() docker.image(myImage.imageName()).inside() workaround for myImage.inside() seems to get around the bug, tho.

          Jesse Glick added a comment -

          I managed to reproduce the problem in a job based on the demo job, but the patch is not as simple as I thought, because an image might be either a local name (for example returned from Docker.build) or a remote name with registry. The originally proposed patch actually breaks the stock demo.

          Jesse Glick added a comment - I managed to reproduce the problem in a job based on the demo job, but the patch is not as simple as I thought, because an image might be either a local name (for example returned from Docker.build ) or a remote name with registry. The originally proposed patch actually breaks the stock demo.

          Jesse Glick added a comment -

          Alternately, perhaps the intention is that when using a registry, all local image names include the prefix, starting with build -t. The documentation is unclear on best practices.

          Jesse Glick added a comment - Alternately, perhaps the intention is that when using a registry, all local image names include the prefix, starting with build -t . The documentation is unclear on best practices.

          Art V added a comment -

          If this helps anyone, for the last few months I've been running with these changes to the plugin to work around this issue..

          diff --git a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          index 196ee39..13ac834 100644
          --- a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          +++ b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          @@ -86,9 +86,10 @@ class Docker implements Serializable {
                           }
                       }
          
          -            script.sh "docker build -t ${image} ${args}"
          -            script.dockerFingerprintFrom dockerfile: dockerfile, image: image, toolName: script.env.DOCKER_TOOL_NAME
          -            this.image(image)
          +            def buildImage = this.image(image)
          +            script.sh "docker build -t ${buildImage.imageName()} ${args}"
          +            script.dockerFingerprintFrom dockerfile: dockerfile, image: buildImage.imageName(), toolName: script.env.DOCKER_TOOL_NAME
          +            buildImage
                   }
               }
          
          @@ -114,12 +115,12 @@ class Docker implements Serializable {
          
                   public <V> V inside(String args = '', Closure<V> body) {
                       docker.node {
          -                if (docker.script.sh(script: "docker inspect -f . ${id}", returnStatus: true) != 0) {
          +                if (docker.script.sh(script: "docker inspect -f . ${imageName()}", returnStatus: true) != 0) {
                               // Not yet present locally.
                               // withDockerContainer requires the image to be available locally, since its start phase is not a durable task.
                               pull()
                           }
          -                docker.script.withDockerContainer(image: id, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
          +                docker.script.withDockerContainer(image: imageName(), args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) {
                               body()
                           }
                       }
          @@ -133,7 +134,7 @@ class Docker implements Serializable {
          
                   public Container run(String args = '', String command = "") {
                       docker.node {
          -                def container = docker.script.sh(script: "docker run -d${args != '' ? ' ' + args : ''} ${id}${command != '' ? ' ' + command : ''}", returnStdout: true).trim()
          +                def container = docker.script.sh(script: "docker run -d${args != '' ? ' ' + args : ''} ${imageName()}${command != '' ? ' ' + command : ''}", returnStdout: true).trim()
                           docker.script.dockerFingerprintRun containerId: container, toolName: docker.script.env.DOCKER_TOOL_NAME
                           new Container(docker, container)
                       }
          @@ -154,7 +155,7 @@ class Docker implements Serializable {
                       docker.node {
                           def taggedImageName = toQualifiedImageName(parsedId.userAndRepo + ':' + tagName)
                           // TODO as of 1.10.0 --force is deprecated; for 1.12+ do not try it even once
          -                docker.script.sh "docker tag --force=${force} ${id} ${taggedImageName} || docker tag ${id} ${taggedImageName}"
          +                docker.script.sh "docker tag --force=${force} ${imageName()} ${taggedImageName} || docker tag ${imageName()} ${taggedImageName}"
                           return taggedImageName;
                       }
                   }
          

          Art V added a comment - If this helps anyone, for the last few months I've been running with these changes to the plugin to work around this issue.. diff --git a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy index 196ee39..13ac834 100644 --- a/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy +++ b/src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy @@ -86,9 +86,10 @@ class Docker implements Serializable { } } - script.sh "docker build -t ${image} ${args}" - script.dockerFingerprintFrom dockerfile: dockerfile, image: image, toolName: script.env.DOCKER_TOOL_NAME - this .image(image) + def buildImage = this .image(image) + script.sh "docker build -t ${buildImage.imageName()} ${args}" + script.dockerFingerprintFrom dockerfile: dockerfile, image: buildImage.imageName(), toolName: script.env.DOCKER_TOOL_NAME + buildImage } } @@ -114,12 +115,12 @@ class Docker implements Serializable { public <V> V inside( String args = '', Closure<V> body) { docker.node { - if (docker.script.sh(script: "docker inspect -f . ${id}" , returnStatus: true ) != 0) { + if (docker.script.sh(script: "docker inspect -f . ${imageName()}" , returnStatus: true ) != 0) { // Not yet present locally. // withDockerContainer requires the image to be available locally, since its start phase is not a durable task. pull() } - docker.script.withDockerContainer(image: id, args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) { + docker.script.withDockerContainer(image: imageName(), args: args, toolName: docker.script.env.DOCKER_TOOL_NAME) { body() } } @@ -133,7 +134,7 @@ class Docker implements Serializable { public Container run( String args = '', String command = "") { docker.node { - def container = docker.script.sh(script: "docker run -d${args != '' ? ' ' + args : ' '} ${id}${command != ' ' ? ' ' + command : ' '}" , returnStdout: true ).trim() + def container = docker.script.sh(script: "docker run -d${args != '' ? ' ' + args : ' '} ${imageName()}${command != ' ' ? ' ' + command : ' '}" , returnStdout: true ).trim() docker.script.dockerFingerprintRun containerId: container, toolName: docker.script.env.DOCKER_TOOL_NAME new Container(docker, container) } @@ -154,7 +155,7 @@ class Docker implements Serializable { docker.node { def taggedImageName = toQualifiedImageName(parsedId.userAndRepo + ':' + tagName) // TODO as of 1.10.0 --force is deprecated; for 1.12+ do not try it even once - docker.script.sh "docker tag --force=${force} ${id} ${taggedImageName} || docker tag ${id} ${taggedImageName}" + docker.script.sh "docker tag --force=${force} ${imageName()} ${taggedImageName} || docker tag ${imageName()} ${taggedImageName}" return taggedImageName; } }

          Code changed in jenkins
          User: Jesse Glick
          Path:
          demo/JENKINS_HOME/jobs/puller/config.xml
          demo/plugins.txt
          src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy
          http://jenkins-ci.org/commit/docker-workflow-plugin/417acf3af06e277071b87a7fec065d6dc50fdcad
          Log:
          [FIXED JENKINS-34276] Allow Image.inside to run with either a local or registry-prefixed name.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: demo/JENKINS_HOME/jobs/puller/config.xml demo/plugins.txt src/main/resources/org/jenkinsci/plugins/docker/workflow/Docker.groovy http://jenkins-ci.org/commit/docker-workflow-plugin/417acf3af06e277071b87a7fec065d6dc50fdcad Log: [FIXED JENKINS-34276] Allow Image.inside to run with either a local or registry-prefixed name.

            jglick Jesse Glick
            radeshrao Radesh Rao
            Votes:
            9 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved: