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 $PATHoutput 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_configfile to enable andPermitUserEnvironmentto yes on the agent machine. Please see the example in the screen shot below:
-
Next you will need to create a
.sshdirectory for the user that the Jenkins connects as to launch the ssh agent if it does not already exist. Then create anenvironmentfile in the.sshdirectory. Theenvironmentfile will contain an entry for PATH and its value (taken from step 1). Please note that the syntax for theenvironmentfile 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
sshdservice for the change instep 2to 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.