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'
}
}
}
}