Issue
A SSH connected agent does not have the same PATH when connecting as that user via remote desktop
PATH for jenkins user when connected via remote desktop image::common-kb::remoteDesktopPath.png[remoteDesktopPath.png]
PATH for jenkins agent when ssh agent is launched from CloudBees Jenkins UI image::common-kb::sshAgentPathNoPermitEnvironment.png[sshAgentPathNoPermitEnvironment.png]
Resolution
The reason for the difference in the PATH environment variable is due to the remote desktop connection using an interactive shell, while the jenkins agent is using a non-interactive shell.
In order to resolve this issue, please do the following:
-
Make a note of the
echo $PATH
output when connected to the agent machine via remote desktop as shown in the PATH for jenkins user when connected via remote desktop screen shot above or from any connection that uses an interactive shell. -
You will need to edit the
etc/ssh/sshd_config
file to enable andPermitUserEnvironment
to yes on the agent machine. Please see the example in the screen shot below: -
Next you will need to create a
.ssh
directory for the user that the Jenkins connects as to launch the ssh agent if it does not already exist. Then create anenvironment
file in the.ssh
directory. Theenvironment
file will contain an entry for PATH and its value (taken from step 1). Please note that the syntax for theenvironment
file is Variable=Value and any additional environment variables can be added on a separate line in this manner. In the example below the jenkins user is used: -
Restart the
sshd
service for the change instep 2
to be picked up. Stop the agent from the Jenkins UI if it is currently connected and relaunch it. The PATH environment variable will now match the output shown in the the PATH for jenkins user when connected via remote desktop screen shot above.