[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Oleksandr Shmyrko commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container Daniel Sorensen, indeed, it works, and that's a good example. I just want to note that passing environment argument to the docker command will override original PATH value defined in image with the one from Jenkins host, and in some conditions it may produce not the result you expect (this was actually described in JENKINS-43590). Here is such example: pipeline { agent any environment { NODEJS_VERSION = "NodeJS 12.16.2" } stages { stage('Nodejs inside OpenJDK container 1') { agent { docker { reuseNode true image 'openjdk:11.0-jdk-slim' args """ -v ${JENKINS_HOME}/tools:${JENKINS_HOME}/tools -e PATH="${PATH}:${tool("${NODEJS_VERSION}")}/bin" """ // Original PATH from openjdk image: // PATH=/usr/local/openjdk-11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin } } tools { nodejs "${NODEJS_VERSION}" } environment { PATH_JENKINS_ORIGINAL = "${PATH}" } steps { sh 'env | sort' sh 'node --version' catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'cannot find java') { sh 'java --version' } } } stage('Nodejs inside OpenJDK container 2') { agent { docker { reuseNode true image 'openjdk:11.0-jdk-slim' args """ -v ${JENKINS_HOME}/tools:${JENKINS_HOME}/tools """ } } tools { nodejs "${NODEJS_VERSION}" } environment { NODEJS_BIN_PATH = "${tool("${NODEJS_VERSION}")}/bin" PATH_JENKINS_ORIGINAL = "${PATH}" } steps { sh ''' env | sort export PATH=${PATH}:${NODEJS_BIN_PATH} node --version java --version ''' } } } } Add Comment
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Daniel Sorensen commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container It now works to set custom PATH inside Docker container in a declarative pipeline by using the environment argument -e to the Docker commands. e.g. agent { docker { image 'amazoncorretto:8u202' label 'docker' args ''' -v $HOME/tools:$HOME/tools -v $HOME/.m2/:$HOME/.m2 -e PATH="$PATH:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/MVN-360/bin" ''' } [Pipeline] sh + env + grep PATH PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/MVN-360/bin Add Comment This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Lukasz Walewski commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container Another workaround is to run commands in a modified environment: pipeline { agent { docker { image 'debian' } } environment { PATH = '/some/dir' } stages { stage('Test') { steps { sh "env PATH=$PATH:\$PATH" } } } } The resulting PATH variable contains /some/dir prepended to the PATH value defined inside the container (observe double quotes in the steps directive). I fully agree with the others, that the option to manipulate the PATH variable inside a container is a must-have. Note, that this feature has nothing to do with setting the PATH inside a container to the value this variable has outside of it, i.e. on the Jenkins node, which would be obviously wrong in most cases. Add Comment This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Nenad Miksa commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container Any update on this issue? The workaround by Paul Theunissen works, but its very ugly and inpractical for some use cases. Add Comment This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.187905.1516636297000.9499.1572973020358%40Atlassian.JIRA.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Rong Shen commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container Thank you Paul Theunissen! Let me have a try Add Comment This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Paul Theunissen commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container I did something like this as workaround: // Get the full PATH variable from a started container. def pathInContainer docker.image(DockerImage).inside() { pathInContainer = steps.sh(script: 'echo $PATH', returnStdout: true).trim() parameters += "-e PATH=${pathInContainer}:/misc/AddExtraPath " } docker.image(DockerImage) .inside(parameters) { runA() runB() } It extracts the PATH from a started container, then stops the container, and starts a new one with the extra PATH environment variable (which I extended with the things required by us). Add Comment This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Rong Shen commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container I'm seeing same issue here. It is definitely necessary to have a way to set PATH variable inside docker container. We have a PATH environment variable is dynamic changing with Jenkins workspace path that can only set through code. Add Comment This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Rong Shen edited a comment on JENKINS-49076 Re: Cannot set custom PATH inside docker container I'm seeing same issue here.It is definitely necessary to have a way to set PATH variable inside docker container. We have a PATH environment variable is dynamic changing with Jenkins workspace path that can only set through code. Is there a workaround for this issue? Add Comment This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Steven Clark edited a comment on JENKINS-49076 Re: Cannot set custom PATH inside docker container I believe this may be the root cause as well with the failures I'm seeing within a declarative pipeline. Running this PATH from the env command is the normal value and not the value within my pipeline . This only seems to break when the agent is a docker {code:java}pipeline { agent { docker { image 'debian:stretch' } } environment { PATH = "/opt/test/bin:/usr/bin/:/bin" } stages { stage('Example') { steps { sh 'env' } } }}{code} Add Comment This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Steven Clark commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container I believe this may be the root cause as well with the failures I'm seeing within a declarative pipeline. Running this PATH from the env command is the normal value. pipeline { agent { docker { image 'debian:stretch' } } environment { PATH = "/opt/test/bin:/usr/bin/:/bin" } stages { stage('Example') { steps { sh 'env' } } } } Add Comment This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-49076) Cannot set custom PATH inside docker container
Title: Message Title Kieran Webber commented on JENKINS-49076 Re: Cannot set custom PATH inside docker container Just ran into this issue using withEnv in a docker container. Works for everything but PATH currently. Add Comment This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.