How To Set Up A Jenkins Agent To Have The Same Path As The User When Connected Via Remote Desktop

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
remoteDesktopPath.png

PATH for jenkins agent when ssh agent is launched from CloudBees Jenkins UI
sshAgentPathNoPermitEnvironment.png

Environment

CloudBees Jenkins

Jenkins

Resolution

The reason for the difference in the PATH environment variable is due to the remote desktop connection
using a interactive shell, while the jenkins agent is using a non-interactive shell.

In order to resolve this issue, please do the following:

  1. Make a note of the echo $PATH output when connected to the slave 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.

  2. You will need to edit the etc/ssh/sshd_config file to enable and PermitUserEnvironment to yes
    on the slave agent machine. Please see the example in the screen shot below:

    sshdConfigPermitEnvironment

  3. 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 an environment file in the .ssh directory. The
    environment file will contain an entry for PATH and its value (taken from step 1). Please note that the
    syntax for the environment 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:

    jenkinsUser.sshDirectory

  4. Restart the sshd service for the change in step 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.

    jenkinsAgentWithMatchingPath

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.