Skip to main content

Jenkins: Home Profile

When Jenkins is installed on a linux host, the Jenkins service and any spawned builds run under the context of the jenkins user account.
Problem is, the jenkins user account is not a regular user account, with a profile that lives under /home.
Instead, the Jenkins user profile is located at: /var/lib/jenkins
This irregularity creates some nuances for several scenarios that assume a normal user profile location, such as:

  • Managing SSH keys
  • Nuget caching
  • NPM caching

The above scenarios, and others, point to the /home folder as where a user profile lives.

So, you will come across many tutorials for installing nuget, or standing up NPM caches, etc, that are all required things for a capable Jenkins build server to have and use.

But, following these instructions will require special care as to what user account will need them, and if they are properly mapped.

There's a couple of ways to find where the jenkins user profile is located.
But since the jenkins user is a system account, without a defined shell, we can't simply login as it and check it's HOME environment variable.

So, the next best thingĀ is to use what Linux uses for storing the home path.
We inspect /etc/passwd.

Opening /etc/passwd and looking for the jenkins user line, shows this:

image.png

We say to use the above technique, because you can't readily login as the jenkins user and run: ECHO $HOME
This is because t
he jenkins account is more like a service account, and has no defined shell.
Plus, we don't easily know what the jenkins password is.

Solution

See this page for details of how to execute commands as a system account: Linux: Impersonating Users

Or, better. Follow the steps on this page to assign a shell and add a profile file to the jenkins system account: Ubuntu: Converting a System Account to Interactive
Doing so, allows your Jenkins build server to run software packages that are normally installed on a per-user basis, such as NVM and NPM.

Examples

We don't yet have a list of things that have to be done with the Jenkins user account.
But, here are some examples, to illustrate the referenced solution:

Installing SSH Keys
sudo -u jenkins mkdir -p /var/lib/jenkins/.ssh
sudo -u jenkins chmod 700 /var/lib/jenkins/.ssh
sudo -u jenkins ssh-keygen -t rsa -b 4096 -f /var/lib/jenkins/.ssh/id_rsa
Configuring Git for a Jenkins User
sudo -u jenkins git config --global user.name "Jenkins CI"
sudo -u jenkins git config --global user.email "jenkins@example.com"
Getting Environment Variables for a User
sudo -u jenkins env