Preserve Environment Variables While Debugging With SSH

Environment Variable Discrepancies

When debugging with SSH the `$PATH` environment will often be different than what may be set in a Dockerfile. For example:

# Update PATH for Java tools
ENV PATH="/opt/sbt/bin:/opt/apache-maven/bin:/opt/apache-ant/bin:/opt/gradle/bin:$PATH"

When SSH'ing into the build, customers may find that `$PATH` is no longer set to that value:

$ echo $PATH


This can be due to the fact that the SSH login with run the bash profile script located at `/etc/profile`.
In order to preserve the `$PATH` environment variable, either modify the `/etc/profile` file within the image or create a new `~/.bash_profile` file in the home directory for the login user. For CircleCI convenience images this would be located at `/home/circleci/.bash_profile`


export PATH="/home/circleci/.local/bin:/home/circleci/bin:/opt/sbt/bin:/opt/apache-maven/bin:/opt/apache-ant/bin:/opt/gradle/bin:/usr/local/openjdk-14/bin:${PATH}"


This can be added to the Dockerfile with the following:

RUN echo "#!/bin/bash\nexport PATH=/home/circleci/.local/bin:/home/circleci/bin:/opt/sbt/bin:/opt/apache-maven/bin:/opt/apache-ant/bin:/opt/gradle/bin:/usr/local/openjdk-14/bin:${PATH}" > /home/circleci/.bash_profile

RUN chmod a+x /home/circleci/.bash_profile


Was this article helpful?
1 out of 3 found this helpful



Article is closed for comments.