Can't move JENKINS_HOME

Hello,
we have a pretty old version of Jenkins running so we decided to create a brand new one and move step by step everything (instead of upgrading that).

To do so I’ve started working on a VM but I got blocked at the beginning, because I can’t move the JENKINS_HOME directory.

Following a few guides I’ve done:

sudo mkdir /home/user/data/jenkins_home
sudo chown jenkins:jenkins /home/user/data/jenkins_home
sudo cp -prv /var/lib/jenkins/* /home/user/data/jenkins_home
sudo usermod -d /home/user/data/jenkins_home jenkins

Then I’ve edited the configuration

sudo systemctl edit jenkins

Adding these lines

[Service]

Environment="JENKINS_HOME=/home/user/data/jenkins_home"
WorkingDirectory=/home/user/data/jenkins_home

With this configuration the error I get is

nov 04 08:50:32 ubuntu22 systemd[1]: jenkins.service: Scheduled restart job, restart counter is at 4.
nov 04 08:50:32 ubuntu22 systemd[1]: Stopped Jenkins Continuous Integration Server.
nov 04 08:50:32 ubuntu22 systemd[1]: Starting Jenkins Continuous Integration Server…
nov 04 08:50:32 ubuntu22 systemd[4661]: jenkins.service: Changing to the requested working directory failed: Permission denied
nov 04 08:50:32 ubuntu22 systemd[4661]: jenkins.service: Failed at step CHDIR spawning /usr/bin/jenkins: Permission denied
nov 04 08:50:32 ubuntu22 systemd[1]: jenkins.service: Main process exited, code=exited, status=200/CHDIR
nov 04 08:50:32 ubuntu22 systemd[1]: jenkins.service: Failed with result ‘exit-code’.
nov 04 08:50:32 ubuntu22 systemd[1]: Failed to start Jenkins Continuous Integration Server

If I remove

WorkingDirectory=/home/user/data/jenkins_home

The error I get is

nov 04 08:58:14 ubuntu22 systemd[1]: jenkins.service: Scheduled restart job, restart counter is at 4.
nov 04 08:58:14 ubuntu22 systemd[1]: Stopped Jenkins Continuous Integration Server.
nov 04 08:58:14 ubuntu22 systemd[1]: Starting Jenkins Continuous Integration Server…
nov 04 08:58:14 ubuntu22 jenkins[4800]: jenkins: /home/user/data/jenkins_home is not a directory
nov 04 08:58:14 ubuntu22 systemd[1]: jenkins.service: Main process exited, code=exited, status=1/FAILURE
nov 04 08:58:14 ubuntu22 systemd[1]: jenkins.service: Failed with result ‘exit-code’.
nov 04 08:58:14 ubuntu22 systemd[1]: Failed to start Jenkins Continuous Integration Server

I’ve tried also a few other things but I never get it running.
What am I missing?

Environment:
Ubuntu 22.04 VM
Jenkins 2.479.1
OpenJDK 17

you must ensure that the jenkins user has access to all intermediate directories as well. So if it’s missing access to /home/user/data it will fail.

Thank you,
I’ve verified in a brand new machine that if I create jenkins account BEFORE installing jenkins and I do all the operation with jenkins account I have no issue.

1 Like