It turns out you can use the environment variables in settings.json
as expected using ${env:your_var}
.
However, once the VS Code server is started, it keeps running even after closing the client VS Code remote connection. All subsequent connections only check for existing VS Code server installation and connect to it. Therefore, when you update your ~/.bashrc
to set additional environment variables, such as:
export HOST=`hostname`
The VS Code server environment will remain unchanged.
The solution is to invoke the Remote-SSH Kill VS Code Server on Host
command in your VS Code client to force-restart the server on your next login. You will notice that after your next login, the VS Code server installation log will show the output of the printenv
command, which should now reflect the updates to the ~/.bashrc
file.
Note on the $HOSTNAME
variable
For some reason, the $HOSTNAME
variable which is usually set when you log in to a machine with an interactive session is not set in the environment of the VS Code server instance - that's why I ended up using a custom variable set in ~/.bashrc
.