'Jenkins home path changes by itself after restarting MacOS. How do I setup JENKINS_HOME?

I installed jenkins-lts from Homebrew using this command.

brew install jenkins-lts

Installation was succesful. Then, I started Jenkins.

brew services start jenkins-lts

which directs me to Unlock Jenkins page. The initial password was contained at

/Users/myusername/.jenkins/secrets/initialAdminPassword

I logged in, install plugins and setup an admin account without any problem. However, after I restarted MacOS, Jenkins home path changes by itself to /var/root/.jenkins. It ignores the admin account I created and prompted me to Unlock Jenkins again by using the password found here:

/var/root/.jenkins/secrets/initialAdminPassword

Then I have to redo setting up another admin account.

My question is: Why does this always happen after I restart MacOS (Catalina version 10.15.7)? How do I setup JENKINS_HOME to /Users/myusername/.jenkins ?



Solution 1:[1]

According with the Jenkins Documentation, it is possible to provide the JENKINS_HOME system properly in the java service such as:

-DJENKINS_HOME=/path/to/jenkins_home/

In this case, as you have installed Jenkins with homebrew, the service file should be located at: /usr/local/opt/jenkins-lts/homebrew.jenkins-lts.service

So you can modify the ExecStart command and add this and other flags as required.

Summary:

  1. Edit the file: /usr/local/opt/jenkins-lts/homebrew.jenkins-lts.service

  2. Add this Flag Before -jar. -DJENKINS_HOME=/path/to/jenkins_home/.

  3. Edit the file /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist by adding the string parameter:

    -DJENKINS_HOME=/Users/myuser/.jenkins

  4. Make sure to pass all of these arguments before the -jar argument

If the previous change didn't worked, alternatively add the DJENKINS_HOME string parameter to the plist /Library/LaunchDaemons/jenkins-lts.plist in the following manner:

<string>-DJENKINS_HOME=/Users/myuser/.jenkins</string>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1