How to change the Home Directory of Jenkins in Linux Mint 20
To Change Home Directory on Jenkins
Introduction:
Jenkins is an open-source automation server that supports automating the components of software development associated with structure, testing, and deploying, facilitating continuous integration and continuous delivery. It also runs in servlet containers including Apache Tomcat.
Procedure:
Check the version of the Linux Mint OS
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description: Linux Mint 20
Release: 20
Codename: ulyana
Now go the Jenkins page and click manage Jenkins and configure system. There you can see the Home directory location.
Create the directory inside the home user directory
root@linuxhelp:~# cd /home/user/
root@linuxhelp:/home/user# mkdir jenkinsnew
Change the ownership of this directory
root@linuxhelp:/home/user# chown -R jenkins:jenkins jenkinsnew
root@linuxhelp:/home/user# ls -la
total 128
drwxr-xr-x 17 user user 4096 Apr 16 03:28 .
drwxr-xr-x 3 root root 4096 Mar 30 13:29 ..
-rw------- 1 user user 54 Apr 2 08:16 .bash_history
-rw-r--r-- 1 user user 220 Mar 30 13:29 .bash_logout
-rw-r--r-- 1 user user 3771 Mar 30 13:29 .bashrc
drwx------ 10 user user 4096 Apr 8 17:12 .cache
drwxrwxr-x 3 user user 4096 Mar 30 14:55 .cinnamon
drwxr-xr-x 14 user user 4096 Mar 30 14:55 .config
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Desktop
-rw-r--r-- 1 user user 27 Mar 30 14:55 .dmrc
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Documents
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Downloads
drwx------ 3 user user 4096 Mar 30 14:55 .gnupg
-rw-r--r-- 1 user user 22 Mar 30 13:29 .gtkrc-2.0
-rw-r--r-- 1 user user 516 Mar 30 13:29 .gtkrc-xfce
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:28 jenkinsnew
drwxr-xr-x 3 user user 4096 Mar 30 13:29 .local
drwx------ 5 user user 4096 Apr 8 17:12 .mozilla
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Music
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Pictures
-rw-r--r-- 1 user user 807 Mar 30 13:29 .profile
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Public
-rw-r--r-- 1 user user 0 Mar 31 13:40 .sudo_as_admin_successful
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Templates
drwxr-xr-x 2 user user 4096 Mar 30 14:55 Videos
-rw------- 1 user user 54 Apr 2 08:12 .Xauthority
-rw------- 1 user user 16183 Apr 16 03:21 .xsession-errors
-rw------- 1 user user 10366 Apr 1 18:52 .xsession-errors.old
Now copy the data’s from the Jenkins directory to newly created directory
root@linuxhelp:/home/user# cd /var/lib/jenkins/
root@linuxhelp:/var/lib/jenkins# ls -la
total 120
drwxr-xr-x 15 jenkins jenkins 4096 Apr 16 03:26 .
drwxr-xr-x 70 root root 4096 Apr 8 17:24 ..
-rw------- 1 jenkins jenkins 80 Apr 16 03:26 .bash_history
drwxr-xr-x 3 jenkins jenkins 4096 Apr 8 17:40 .cache
drwx------ 3 jenkins jenkins 4096 Apr 8 17:24 .config
-rw-r--r-- 1 jenkins jenkins 1597 Apr 8 17:26 config.xml
drwxr-xr-x 3 jenkins jenkins 4096 Apr 8 18:43 .groovy
-rw-r--r-- 1 jenkins jenkins 156 Apr 8 17:25 hudson.model.UpdateCenter.xml
-rw-r--r-- 1 jenkins jenkins 1243 Apr 16 03:21 hudson.plugins.emailext.ExtendedEmailPublisher.xml
-rw-r--r-- 1 jenkins jenkins 370 Apr 8 18:43 hudson.plugins.git.GitTool.xml
-rw------- 1 jenkins jenkins 1712 Apr 8 17:25 identity.key.enc
drwxr-xr-x 3 jenkins jenkins 4096 Apr 8 17:25 .java
-rw-r--r-- 1 jenkins jenkins 7 Apr 8 18:45 jenkins.install.InstallUtil.lastExecVersion
-rw-r--r-- 1 jenkins jenkins 7 Apr 8 18:45 jenkins.install.UpgradeWizard.state
-rw-r--r-- 1 jenkins jenkins 171 Apr 8 17:25 jenkins.telemetry.Correlator.xml
drwxr-xr-x 2 jenkins jenkins 4096 Apr 8 17:25 jobs
-rw-r--r-- 1 jenkins jenkins 0 Apr 8 17:26 .lastStarted
drwxr-xr-x 3 jenkins jenkins 4096 Apr 8 17:25 logs
-rw-r--r-- 1 jenkins jenkins 907 Apr 8 17:25 nodeMonitors.xml
drwxr-xr-x 2 jenkins jenkins 4096 Apr 8 17:25 nodes
-rw-r--r-- 1 jenkins jenkins 44 Apr 8 18:36 .owner
drwxr-xr-x 80 jenkins jenkins 12288 Apr 8 18:42 plugins
-rw-r--r-- 1 jenkins jenkins 129 Apr 16 03:25 queue.xml
-rw-r--r-- 1 jenkins jenkins 64 Apr 8 17:25 secret.key
-rw-r--r-- 1 jenkins jenkins 0 Apr 8 17:25 secret.key.not-so-secret
drwx------ 4 jenkins jenkins 4096 Apr 16 03:19 secrets
drwxr-xr-x 2 jenkins jenkins 4096 Apr 8 18:43 updates
drwxr-xr-x 2 jenkins jenkins 4096 Apr 8 17:25 userContent
drwxr-xr-x 3 jenkins jenkins 4096 Apr 8 17:25 users
Now switch to the Jenkins user and copy the files to the directory
root@linuxhelp:/var/lib/jenkins# su Jenkins
jenkins@linuxhelp:~$ cp -r * .bash_history .config .java .owner .lastStarted .groovy .cache /home/user/jenkinsnew
Now stop the Jenkins service
root@linuxhelp:/home/user/jenkinsnew# systemctl stop jenkins
Now list the newly created Jenkins directory and list the directory
root@linuxhelp:/home/user/jenkinsnew# ls -la
total 112
drwxr-xr-x 15 jenkins jenkins 4096 Apr 16 03:32 .
drwxr-xr-x 17 user user 4096 Apr 16 03:28 ..
-rw------- 1 jenkins jenkins 173 Apr 16 03:32 .bash_history
drwxr-xr-x 3 jenkins jenkins 4096 Apr 16 03:32 .cache
drwx------ 3 jenkins jenkins 4096 Apr 16 03:32 .config
-rw-r--r-- 1 jenkins jenkins 1597 Apr 16 03:32 config.xml
drwxr-xr-x 3 jenkins jenkins 4096 Apr 16 03:32 .groovy
-rw-r--r-- 1 jenkins jenkins 156 Apr 16 03:32 hudson.model.UpdateCenter.xml
-rw-r--r-- 1 jenkins jenkins 1243 Apr 16 03:32 hudson.plugins.emailext.ExtendedEmailPublisher.xml
-rw-r--r-- 1 jenkins jenkins 370 Apr 16 03:32 hudson.plugins.git.GitTool.xml
-rw------- 1 jenkins jenkins 1712 Apr 16 03:32 identity.key.enc
drwxr-xr-x 3 jenkins jenkins 4096 Apr 16 03:32 .java
-rw-r--r-- 1 jenkins jenkins 7 Apr 16 03:32 jenkins.install.InstallUtil.lastExecVersion
-rw-r--r-- 1 jenkins jenkins 7 Apr 16 03:32 jenkins.install.UpgradeWizard.state
-rw-r--r-- 1 jenkins jenkins 171 Apr 16 03:32 jenkins.telemetry.Correlator.xml
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:32 jobs
-rw-r--r-- 1 jenkins jenkins 0 Apr 16 03:32 .lastStarted
drwxr-xr-x 3 jenkins jenkins 4096 Apr 16 03:32 logs
-rw-r--r-- 1 jenkins jenkins 907 Apr 16 03:32 nodeMonitors.xml
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:32 nodes
-rw-r--r-- 1 jenkins jenkins 44 Apr 16 03:32 .owner
drwxr-xr-x 80 jenkins jenkins 4096 Apr 16 03:32 plugins
-rw-r--r-- 1 jenkins jenkins 129 Apr 16 03:32 queue.xml
-rw-r--r-- 1 jenkins jenkins 64 Apr 16 03:32 secret.key
-rw-r--r-- 1 jenkins jenkins 0 Apr 16 03:32 secret.key.not-so-secret
drwx------ 4 jenkins jenkins 4096 Apr 16 03:32 secrets
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:32 updates
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:32 userContent
drwxr-xr-x 3 jenkins jenkins 4096 Apr 16 03:32 users
drwxr-xr-x 2 jenkins jenkins 4096 Apr 16 03:32 workflow-libs
Now we have to change the JENKINS_HOME directory from the following file location
root@linuxhelp:/home/user/jenkinsnew# vim /etc/default/jenkins
root@linuxhelp:/home/user/jenkinsnew# vim /etc/passwd
Finally start enable and check the status of the Jenkins service
root@linuxhelp:/home/user/jenkinsnew# systemctl start jenkins
root@linuxhelp:/home/user/jenkinsnew# systemctl enable jenkins
jenkins.service is not a native service, redirecting to systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable jenkins
root@linuxhelp:/home/user/jenkinsnew# systemctl status jenkins
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Fri 2021-04-16 03:36:19 IST; 43s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 4583)
Memory: 0B
CGroup: /system.slice/jenkins.service
Apr 16 03:36:16 linuxhelp systemd[1]: Starting LSB: Start Jenkins at boot time...
Apr 16 03:36:17 linuxhelp jenkins[65952]: Correct java version found
Apr 16 03:36:17 linuxhelp jenkins[65952]: * Starting Jenkins Automation Server jenkins
Apr 16 03:36:17 linuxhelp su[65995]: (to jenkins) root on none
Apr 16 03:36:17 linuxhelp su[65995]: pam_unix(su-l:session): session opened for user jenkins by (uid=0)
Apr 16 03:36:19 linuxhelp jenkins[65952]: ...done.
Apr 16 03:36:19 linuxhelp systemd[1]: Started LSB: Start Jenkins at boot time.
Now go the Jenkins page reload and click manage Jenkins and configure system. There you can see the Home directory location is changed successfully.
And build tools like Apache Maven.