DEV Community

polroyal
polroyal

Posted on

migrating jenkins home directory in linux

I recently had an issue with my Jenkins server complaining of not enough space in the partition and directory where it was installed on my Centos 7 OS. This obviously is the default ‘va/lib/jenkins directory.

A couple of tries and solutions seemed to work until Jenkins was spinning again and the problem seemed to persist. After some struggles I managed to make Jenkins happy and decided to put together what I believe would be the best solution to migrating the Jenkins default home directory to a new one with enough space.

The following command should quickly tell which partitions have enough space

[root@pol pol]# df -h

Remember to stop the jenkins service before starting the process.

[root@pol pol]# systemctl stop jenkins

We start by creating a new Jenkins directory within the /home/ directory

[root@pol pol]# mkdir /home/jenkins/

Copy all the contents of the old jenkins directory to the new one

[root@pol pol]# cp -rvf /var/lib/jenkins/* /home/jenkins/

Once the copy operation is completed, we need to update the environment variable for Jenkins home directory(JENKINS_HOME). This can be done with the following command

[root@pol pol]# export JENKINS_HOME=/home/jenkins

Jenkins home directory has now been changed but we need to make sure those changes hold even after a reboot. We navigate to the ‘bash_profile’ file located in the /home directory

root@pol home]# vim ~/.bash_profile

We then make the following entry at the bottom of the file

export JENKINS_HOME=/home/jenkins

We also should navigate to the jenkins config file and change the PATH to the new home directory.

[root@pol pol]# vim /etc/sysconfig/jenkins

Change from JENKINS_HOME="/var/lib/jenkins" to the following

JENKINS_HOME="/home/jenkins"

Before restarting the service we need to recursively take care of directory access rights for the jenkins user and group otherwise Jenkins will not be happy with our actions!

chown -R jenkins:jenkins $JENKINS_HOME

The last step would be to restart the jenkins service to implement the changes

[root@pol pol]# systemctl start jenkins

Now if you log back into the Jenkins GUI the home direction should not complain and should be changed!

Top comments (0)