$PATH env var is overwriten in worker containers

For deployments I use a custom Ubuntu 18.04 Docker container. This container is spun up by a dynamic host Ubuntu worker provided by Octopus Cloud.

This container has been modified with tools that we require for deployments. One of the modifications is the installation of NodeJS via Node Version Manager (nvm). The specified default node version being 14.5.0.

As part of the install /etc/environment is updated so the $PATH environment variable contains the install path of node, npm, and other packages installed globally via npm.

The full $PATH environment variable looks like: /root/.nvm/versions/node/v14.5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

The problem is, when running a step that uses node/npm; these binaries cannot be found as the path is overwritten to be the default: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (notice that /root/.nvm/versions/node/v14.5.0/bin is no longer there)

running cat /etc/environment shows that the file has been completely overwritten.

Is there a way to set environment variables in Octopus when defining the process?
Is there a way to stop the $PATH environment variable being overwritten?


For those that may have a similar issue, the work around is to symlink the node, npm, etc binaries to /usr/bin, this way an updated $PATH is not needed.

Regardless, I am sure there will come a time where we will need to set an environment variable as part of a deployment.

Hi @platform_admin!

This is interesting indeed - I don’t think it’s an issue with Octopus overwriting path variables from my brief testing. I spun up a quick repro here, where basically I modified the local path on the worker, then ran a step on the execution container to see how it compared to the path on the container, and it didn’t overwrite any of the system default settings with the ones on the docker host.

When our worker runs it, it’s just a

docker run --rm --env TentacleHome=/home/Octopus -w /home/Octopus/Work/20210203213943-59005-8 -v /home/Octopus/Work/20210203213943-59005-8:/home/Octopus/Work/20210203213943-59005-8 -v /home/Octopus:/home/Octopus
(with the work folders being generated per-deployment, naturally)

If you run your custom container with docker run outside of octopus do you see the same behavior?

Are you able to work around this by adjusting your final script (the one that gets executed on the container) to have the correct path? i.e adding a line with PATH=$PATH:/root/.nvm/versions/node/v14.5.0. Obviously not the most ideal solution, but it should do what you need until we get to the bottom of this.

Please let me know how you go with your investigation, and if you have any further questions.