In my Dockerfile I install Ant and declare environment variables pointing to this Ant installation:
FROM openjdk:7# Install wgetRUN apt-get update \ && apt-get install -y wget \ && rm -rf /var/lib/apt/lists/*# Install antENV ANT_VERSION 1.9.6RUN cd && \ wget -q http://archive.apache.org/dist/ant/binaries/apache-ant-${ANT_VERSION}-bin.tar.gz && \ tar -xzf apache-ant-${ANT_VERSION}-bin.tar.gz && \ mv apache-ant-${ANT_VERSION} /opt/ant && \ rm apache-ant-${ANT_VERSION}-bin.tar.gzENV ANT_HOME /opt/antENV PATH ${PATH}:/opt/ant/bin# Create user jenkinsRUN groupadd -g 999 dockerRUN useradd jenkins -u 999 -g 999 --shell /bin/bash --create-homeRUN echo 'export ANT_HOME=/opt/ant' >> /home/jenkins/.bashrcRUN echo 'export PATH=$PATH:/opt/ant/bin' >> /home/jenkins/.bashrcUSER jenkins As you can see I do 2 things: I use the docker ENV statement which should set the environment variables, then additionally I add export statements to the jenkins' user bashrc. However, inside my Jenkins pipeline these environment variables don't appear to be set, no matter what I do. When I echo my path I see the following: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/jenkins/bin:/usr/lib/oracle/12.1/client64/bin:/usr/lib/oracle/12.1/client64/lib When I echo my .bashrc there are indeed the following lines: export ANT_HOME=/opt/ant export PATH=$PATH:/opt/ant/bin So why is my path set incorrectly? I suspect the reason is that Jenkins overwrites the path when running docker, and I can kinda see this in the console output of Jenkins: docker run -t -d -u 999:999 -w /opt/jenkins/workspace/testws -v /opt/jenkins/workspace/testws :/opt/jenkins/workspace/testws :rw -v /opt/jenkins/workspace/testws @tmp:/opt/jenkins/workspace/testws@tmp:rw -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat 4b4e7722d454ad10aec20f95d2bb1c1ce527c880 And if I look in the documentation it even says how to set environment variables: https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Environment-variables But this doesn't make sense to me. Isn't the whole point of using Docker that your environment will consistently be the same? So why would I want to use environment settings or tools from jenkins if I'm using docker? Then the environment is also not defined in a file anymore. Is there any way around this? Or am I looking at it all wrong? This is the Jenkinsfile that I use: pipeline { agent { dockerfile { label "docker" } } stages { stage("build") { steps { sh 'echo $PATH' sh 'cat ~/.bashrc' } } }} -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9112754e-17f2-44fc-a63e-5cc66d7e0fec%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
