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

DockerClient.version doesn't use build environment

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When running this simple declarative pipeline script:

       

      pipeline {
          agent any
          
          stages {
              stage('setup') {
                  steps {
                      sh "env"
                      sh "docker -v"
                  }    
              }
              
              stage('Test') {
                  agent {
                      docker { image 'ruby' }
                  }
                  
                  steps {
                      echo "in docker"
                      sh 'ruby --version'
                  }
              }
          }
      }

       

       

      my jenkins fails with the error message:
      Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory

      The first call to docker works fine. It downloads the image and is able to call:
      inspect -f . ruby
      The following code path fails:

       

      DockerClient dockerClient = new DockerClient(launcher, node, toolName);
      VersionNumber dockerVersion = dockerClient.version();
      

      The docker client launches docker like this:

       

      public @CheckForNull VersionNumber version() throws IOException, InterruptedException {
       LaunchResult result = launch(new EnvVars(), true, "-v");
       if (result.getStatus() == 0) {
       return parseVersionNumber(result.getOut());
       } else {
       return null;
       }
      }

      As we can see here it instantiates a new EnvVars object. This passed down to the launch method.

       

      In my case this fails because the docker executable is not in the path by default. I updated the path on the Jenkins Configuration (which works because I can use docker to download the image).

      I can only solve this issue at the moment by having docker in the PATH during startup of Jenkins. Setting the tool location also yielded no result because the toolName passed to DockerClient is always null (step.toolName). I couldn't figure out the magic incantation to get the DockerTool locator to work in a declarative pipeline (org.jenkinsci.plugins.docker.commons.tools.DockerTool).

       

        Attachments

          Activity

          Hide
          lkraider Paul Eipper added a comment - - edited

          I have the same issue by just building an image and trying to get the reference to it:

          Jenkinsfile
          node(docker) {
              stage('Build image') {
                  builtImage = docker.build("corp/api:1.0", ".")
              }
          }
          

          The stack trace generated is:

          (...)
          Successfully built 9a71968963a9
          Successfully tagged corp/api:1.0
          [Pipeline] dockerFingerprintFrom
          [Pipeline] }
          [Pipeline] // stage
          [Pipeline] }
          [Pipeline] // node
          [Pipeline] End of Pipeline
          java.io.IOException: error=2, No such file or directory
          	at java.lang.UNIXProcess.forkAndExec(Native Method)
          	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
          	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
          	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
          Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to zerg
          		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1693)
          		at hudson.remoting.UserResponse.retrieve(UserRequest.java:310)
          		at hudson.remoting.Channel.call(Channel.java:908)
          		at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1053)
          		at hudson.Launcher$ProcStarter.start(Launcher.java:450)
          		at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296)
          		at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277)
          		at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274)
          		at org.jenkinsci.plugins.docker.workflow.client.DockerClient.inspect(DockerClient.java:198)
          		at org.jenkinsci.plugins.docker.workflow.client.DockerClient.inspectRequiredField(DockerClient.java:218)
          		at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:129)
          		at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:85)
          		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)
          Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
          	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
          	at hudson.Proc$LocalProc.<init>(Proc.java:249)
          	at hudson.Proc$LocalProc.<init>(Proc.java:218)
          	at hudson.Launcher$LocalLauncher.launch(Launcher.java:930)
          	at hudson.Launcher$ProcStarter.start(Launcher.java:450)
          	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1299)
          	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1260)
          	at hudson.remoting.UserRequest.perform(UserRequest.java:207)
          	at hudson.remoting.UserRequest.perform(UserRequest.java:53)
          	at hudson.remoting.Request$2.run(Request.java:358)
          	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
          	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          	at java.lang.Thread.run(Thread.java:748)
          

          The environment is running with master macOS machine and a slave macOS machine.
          Only the slave has docker installed.

          The install location on the slave for the docker binary is in /usr/local/bin, which is not by default in PATH.

          It is set as an extra variable on the executor configuration by setting an environment variable named PATH+LOCALBIN with value /usr/local/bin.

          Show
          lkraider Paul Eipper added a comment - - edited I have the same issue by just building an image and trying to get the reference to it: Jenkinsfile node(docker) { stage( 'Build image' ) { builtImage = docker.build( "corp/api:1.0" , "." ) } } The stack trace generated is: (...) Successfully built 9a71968963a9 Successfully tagged corp/api:1.0 [Pipeline] dockerFingerprintFrom [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.forkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:247) at java.lang.ProcessImpl.start(ProcessImpl.java:134) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to zerg at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1693) at hudson.remoting.UserResponse.retrieve(UserRequest.java:310) at hudson.remoting.Channel.call(Channel.java:908) at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1053) at hudson.Launcher$ProcStarter.start(Launcher.java:450) at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296) at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277) at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274) at org.jenkinsci.plugins.docker.workflow.client.DockerClient.inspect(DockerClient.java:198) at org.jenkinsci.plugins.docker.workflow.client.DockerClient.inspectRequiredField(DockerClient.java:218) at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:129) at org.jenkinsci.plugins.docker.workflow.FromFingerprintStep$Execution.run(FromFingerprintStep.java:85) 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) Caused: java.io.IOException: Cannot run program "docker" : error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) at hudson.Proc$LocalProc.<init>(Proc.java:249) at hudson.Proc$LocalProc.<init>(Proc.java:218) at hudson.Launcher$LocalLauncher.launch(Launcher.java:930) at hudson.Launcher$ProcStarter.start(Launcher.java:450) at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1299) at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1260) at hudson.remoting.UserRequest.perform(UserRequest.java:207) at hudson.remoting.UserRequest.perform(UserRequest.java:53) at hudson.remoting.Request$2.run(Request.java:358) at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang. Thread .run( Thread .java:748) The environment is running with master macOS machine and a slave macOS machine. Only the slave has docker installed. The install location on the slave for the docker binary is in /usr/local/bin , which is not by default in PATH. It is set as an extra variable on the executor configuration by setting an environment variable named PATH+LOCALBIN with value /usr/local/bin .

            People

            • Assignee:
              Unassigned
              Reporter:
              larusso Manfred Endres
            • Votes:
              3 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: