I'm trying to use a docker machine in Jenkins, and have that machine have an environment variable (FOO) set. I've successfully setup an image using a docker template in my jenkins configuration. Meaning, that's probably not my problem spot. The problem is that I cannot seem to get the environment variable to be available. If I create a jenkins project that just tries to do "echo $FOO", all I get is a blank line.
My Dockerfile is based on ubuntu-14.04, and ends with:
CMD ["/usr/sbin/sshd", "-D"]
Things that I've tried:
In the jenkins configuration page, in the "docker template" section, I've added "FOO=1" to the "environment" field. However, when I click "save", this change is not saved.
Adding to the Dockerfile various ways to set FOO:
RUN echo "export FOO=1" >> /etc/profile
ENV FOO 1
RUN echo export FOO=1 >> ~/.bashrc
EnvInject Plugin. This works, but requires you to check the checkbox in every single jenkins plan. I'm hoping for a solution where I only have to do something once.
References:
Jenkins bug. You cannot set FOO in the Jenkins environment and expect it to be passed to the docker container.
Docker's advice. This page suggests (I think) adding the env variable to /etc/profile. As I mentioned, this failed for me.
Passing env through ssh. This explains how you can modify an ssh call to pass env vars, but I don't know how to access that part of the command within jenkins. (Note, it's fine to expose the variable on the command line.)
ssh set user env. This answer seemed a bit overkill, and I didn't test to see if it worked. Presumably I would have the Dockerfile add .ssh/environment and I would have to enable PermitUserEnvironment.