Recently I came across an issue where the Jenkins server stopped working as the partition on which the Jenkins server was installed was full. & since we could not free up any space on the partition as some other applications were installed on it, we decided that we change the Jenkins home directory.
So I decided that I should the procedure with you guys. In this tutorial, we will learn how we change the home directory of the Jenkins server. So let’s start.....
(Recommended Read: Install Gitlab on Ubuntu & CentOS : A complete guide )
(Also Read: Complete “Beginners to PRO” guide for GIT commands )
Change home directory of Jenkins Server
Firstly locate the current directory for the Jenkins server. You can find the location of the current home directory of the Jenkins server by logging into the Jenkins page. Once logged in, go to ‘Manage Jenkins’ & select the options ‘Configure System’. Here the first thing you will see will be the path to your Home Directory.
Now we will create a new folder for keeping the Jenkins. For this tutorial, we will create a new folder in our home directory.
$ sudo mkdir ~/jenkins
Now copy all the content from the original Jenkins home to this directory,
$ cp -rvf /varlib/jenkins/* ~/jenkins
Once the copy operation has been completed, we will update the environment variable for the home directory. Environment Variable for Jenkins is ‘JENKINS_HOME’, we can update the env variable with the following command,
$ export JENKINS_HOME=~/jenkins
The home directory for the Jenkins has been changed but the updated values for the env variable will only hold for the current session. To permanently update the variable, we need to make changes in the ‘.bash_profile’ file located in our home directory & make the following entry,
$ sudo vi ~/.bash_profile
Now the last step is to restart the Jenkins service to implement the changes,
$ sudo service jenkins restart
Now check the updated path again by logging into the Jenkins webpage. You should now see the updated path for the home directory.
So this completes our tutorial on how we can change the home directory for the Jenkins server. Hope this was helpful to you. Please do leave any queries or suggestions using the comment box below.