Issue
Control environment variables inside a Docker container with the Docker Pipeline plugin.
Environment
- CloudBees Jenkins Enterprise
- Pipeline plugin
- Docker Pipeline plugin
Resolution
By default, when using the Docker Pipeline plugin the node’s environment variables will not be propagated to the docker container - since with Docker you want to get isolate environments. You can check this here
However, if at Node level (http/s://<JENKINS_URL>/computer/<MY_AGENT>/configure), under Node Properties, you add Environment variables, those will be added to the container.
If you would like to override again what is injected at Node level then you will need to use withEnvstep
.
node ('linux-slave') {
withEnv(['PATH=/usr/local/Cellar/coreutils/8.25/libexec/gnubin:/usr/local/Cellar/gnu-sed/4.2.2/libexec/gnubin:/Users/fbelzunc/cloudbees/support/support-shinobi-tools:/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home//bin:/Users/fbelzunc/bin:/usr/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/local/sbin:/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/bundler-1.6.5/bin:/usr/local/Cellar/ruby/2.1.0/lib/ruby/gems/2.1.0/gems/beaker-1.16.0/bin:/usr/local/Cellar/ruby/2.1.0/bin/:/path/testing']) {
docker.image('maven:3.3.3-jdk-8').inside {
sh 'echo $PATH'
sh 'mvn --version'
}
}
sh 'echo $PATH'
}
1 Comments