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

DockerClient.version doesn't use build environment

XMLWordPrintable

      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).

       

            Unassigned Unassigned
            larusso Manfred Endres
            Votes:
            4 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: