jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-49076] Cannot set custom PATH inside docker container

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

Description

I'm trying to set a custom PATH in a docker.image('...').inside block.

For example, I would like to be able to do something like this:

node('docker') {

docker.image('some-build-image').inside {
sh 'echo $PATH'
withEnv(['PATH+MAVEN=/opt/maven-3.3.3/bin']) {
sh 'echo $PATH'
sh 'mvn --version'
}
}
}

But the PATH environment variable inside the docker image does not get updated - the two echo statements produce exactly the same output, and the Maven command fails with the following error: "mvn: command not found"

I see that as a result of #JENKINS-43590, the PATH env var is no longer passed from the host to the docker container (which seems sensible, as the environments can be different), but I feel it should still possible to manipulate the PATH variable inside the docker container somehow, e.g by using withEnv. Even a workaround like running the shell step sh 'export PATH=$PATH:/opt/maven-3.3.3/bin' does not have the required outcome.

---
Originally reported by robin_smith, imported from: Cannot set custom PATH inside docker container


  • status: Open
  • priority: Major
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 21
  • watchers: 27
  • imported: 2025-12-07

Raw content of original issue

I'm trying to set a custom PATH in a docker.image('...').inside block.

For example, I would like to be able to do something like this:



node('docker') {

docker.image('some-build-image').inside {
sh 'echo $PATH'
withEnv(['PATH+MAVEN=/opt/maven-3.3.3/bin']) {
sh 'echo $PATH'
sh 'mvn --version'
}
}
}

But the PATH environment variable inside the docker image does not get updated - the two echo statements produce exactly the same output, and the Maven command fails with the following error: "mvn: command not found"

I see that as a result of #JENKINS-43590, the PATH env var is no longer passed from the host to the docker container (which seems sensible, as the environments can be different), but I feel it should still possible to manipulate the PATH variable inside the docker container somehow, e.g by using withEnv. Even a workaround like running the shell step sh 'export PATH=$PATH:/opt/maven-3.3.3/bin' does not have the required outcome.

environment

```
Jenkins 2.89.3

docker-workflow 1.14
```

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.