jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-47415] DockerClient.version doesn't use build environment

Open
#524 1 comment 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin imported-jira-issue pipeline priority:major resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

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

 

---
Originally reported by larusso, imported from: DockerClient.version doesn't use build environment


  • status: Open
  • priority: Major
  • component(s): docker-workflow-plugin
  • label(s): Docker, declarative, pipeline
  • resolution: Unresolved
  • votes: 4
  • watchers: 4
  • imported: 2025-12-07

Raw content of original issue

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

 

  • environment: mac os 10.12.6, Jenkins 2.83

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.