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

Docker inspect failing on named multi-stage builds

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: docker-workflow-plugin
    • Labels:
      None
    • Environment:
      Debian Jessie x64
      Docker Pipeline 1.11
      Jenkins ver. 2.46.3
      Docker version 17.05.0-ce, build 89658be
    • Similar Issues:
    • Released As:
      docker-workflow 1.19

      Description

      When using named stages in a multistage build as in the example below, the Jenkins pipeline will fail with the following message right after the build has finished.

      <SNIP>
      Successfully built b59ee5bc6b07
      Successfully tagged bytesheep/odr-dabmux:latest
      [Pipeline] dockerFingerprintFrom
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      java.io.IOException: Cannot retrieve .Id from 'docker inspectalpine:3.6 AS builder'
          at org.jenkinsci.plugins.docker.workflow.client.DockerClient.inspectRequiredField(DockerClient.java:193)
          at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:119)
          at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:75)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
          at hudson.security.ACL.impersonate(ACL.java:260)
          at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
          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:748)
      Finished: FAILURE

       

      Dockerfile

      #
      # Build environment
      #
      FROM alpine:3.6 AS builder
      
      <SNIP>
      
      #
      # Create final container
      #
      FROM alpine:3.6
      
      <SNIP>
      
      # Copy artifacts from builder
      COPY --from=builder /usr/local .
      

       

      There is a workaround to this issue by removing the names and using the build numbers instead. example:

      FROM alpine:3.6
      
      <SNIP>
      
      FROM alpine:3.6
      
      COPY --from=0 /usr/local .

       

      Looking at the related source at #100, it seems the code determains the image name looking at FROM and taking everything until EOL. Which would include 'AS buildname'.

      At a glance it also looks like the code will take the first stage for fingerprinting instead of the final stage (which is the resulting image).

        Attachments

          Issue Links

            Activity

            Hide
            skullclown Steven Weathers added a comment -

            Jesse Glick that's one thing I tried but makes things like deploying to registry more of a hassle.  Overall I've since abandoned trying to use Jenkins and have gone with another CI that worked flawlessly from the start since it was docker oriented.

            Show
            skullclown Steven Weathers added a comment - Jesse Glick that's one thing I tried but makes things like deploying to registry more of a hassle.  Overall I've since abandoned trying to use Jenkins and have gone with another CI that worked flawlessly from the start since it was docker oriented.
            Hide
            jglick Jesse Glick added a comment -

            makes things like deploying to registry more of a hassle

            For what it’s worth, my recommendation is

            withDockerRegistry(url: 'https://docker.corp/', credentialsId: 'docker-creds') {
              sh 'sh build-and-push'
            }
            

            with the script being something like

            docker build -t docker.corp/x/y:$TAG .
            docker push docker.corp/x/y:$TAG
            
            Show
            jglick Jesse Glick added a comment - makes things like deploying to registry more of a hassle For what it’s worth, my recommendation is withDockerRegistry(url: 'https: //docker.corp/' , credentialsId: 'docker-creds' ) { sh 'sh build-and-push' } with the script being something like docker build -t docker.corp/x/y: $TAG . docker push docker.corp/x/y: $TAG
            Hide
            taylorp36 Taylor Patton added a comment - - edited

            Also seeing this same issue, but interestingly enough, it works in 1 job but not another, doing almost the exact same thing.

            Working code in question:

            docker.build('mydockerimage', "--file ${DOCKERFILE} --pull --build-arg BUILD_NUMBER=${BUILD_NUMBER} .")

            Code that doesn't work:

            docker.build('mydockerimage', "--file ${myProperties.DOCKERFILE} --pull --build-arg BUILD_NUMBER=${params.BUILD_TO_DEPLOY} .")

            Where "myProperties" is read from a properties file using "readProperties" from stage utils plugin. The docker image seems to be built fine in both cases, but in the latter, we see the error:

            Successfully built 204ce2321dab
            Successfully tagged <redacted>
            [Pipeline] dockerFingerprintFrom
            [Pipeline] }
            [Pipeline] // withCredentials
            [Pipeline] }
            [Pipeline] // withDockerRegistry
            [Pipeline] }
            [Pipeline] // withEnv
            [Pipeline] }
            [Pipeline] // stage
            [Pipeline] }
            [Pipeline] // node
            [Pipeline] End of Pipeline
            java.io.IOException: Cannot retrieve .Id from 'docker inspect<redacted>'

            We do use the multi-stage docker build with "AS name" for the docker stages in the starting Dockerfile being built.

            Show
            taylorp36 Taylor Patton added a comment - - edited Also seeing this same issue, but interestingly enough, it works in 1 job but not another, doing almost the exact same thing. Working code in question: docker.build( 'mydockerimage' , "--file ${DOCKERFILE} --pull --build-arg BUILD_NUMBER=${BUILD_NUMBER} ." ) Code that doesn't work: docker.build( 'mydockerimage' , "--file ${myProperties.DOCKERFILE} --pull --build-arg BUILD_NUMBER=${params.BUILD_TO_DEPLOY} ." ) Where "myProperties" is read from a properties file using "readProperties" from stage utils plugin. The docker image seems to be built fine in both cases, but in the latter, we see the error: Successfully built 204ce2321dab Successfully tagged <redacted> [Pipeline] dockerFingerprintFrom [Pipeline] } [Pipeline] // withCredentials [Pipeline] } [Pipeline] // withDockerRegistry [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.io.IOException: Cannot retrieve .Id from 'docker inspect<redacted>' We do use the multi-stage docker build with "AS name" for the docker stages in the starting Dockerfile being built.
            Hide
            dbensoussan david bensoussan added a comment -

            There is a PR solving this here: https://github.com/jenkinsci/docker-workflow-plugin/pull/162

            Could a maintainer take a look at it?

            Show
            dbensoussan david bensoussan added a comment - There is a PR solving this here: https://github.com/jenkinsci/docker-workflow-plugin/pull/162 Could a maintainer take a look at it?
            Hide
            dnusbaum Devin Nusbaum added a comment -

            A fix for this issue was just released in Docker Pipeline plugin version 1.19. From the release notes: 

            Deprecate the dockerFingerprintFrom and dockerFingerprintRun steps and stop calling them during docker.build and image.run. Fixes various issues with Dockerfile parsing and parsing arguments to docker build.

            Show
            dnusbaum Devin Nusbaum added a comment - A fix for this issue was just released in Docker Pipeline plugin version 1.19. From the release notes:  Deprecate the  dockerFingerprintFrom  and  dockerFingerprintRun  steps and stop calling them during  docker.build  and  image.run . Fixes various issues with Dockerfile parsing and parsing arguments to  docker build .

              People

              • Assignee:
                esmalling Eric Smalling
                Reporter:
                m4rcu5 Marcus van Dam
              • Votes:
                42 Vote for this issue
                Watchers:
                54 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: