Upgrade Jenkins CI withourt losing User/Job Config - jenkins

I would like to upgrade Jenkins to the latest version without losing job/user configuration.
From looking through various posts the answer seems to be to replace the jenkins war directory.
I did this and although the new version seems to be in place the about dialogue still has the original version,
I think this is because the versionnumber is held in a config file outside of the war folder.
Is there a better method to upgrade.

I have the best practice with replacing jenkins.war file, content of the folder should got extracted from war file during server startup (automatically).
All configuration is stored as files in jenkins home directory.
jobs in subfolder jobs, users in users etc.
So if you will replace war file, you will dont loose the configuration or content.
You can check this for better info, looks for "Install the New Jenkins War File
"

I am sharing my experience here, as this would definitely help someone. We were on jenkins 2.138.3 and wanted to upgrade to 2.235.5 version. Now the issue we were facing is our users were getting deleted when we tried to restore the users folder from the backup of old jenkins.
Root Cause: In the jenkins upgrade the mechanism to store the users on the disk is changed. This is verified by seeing the users//config.xml of both old and new jenkins.
The first problem we faced starting the jenkins is below error
java.nio.file.DirectoryNotEmptyException: /Users/jenkins/<username>
The reason being, in the upgraded jenkins the username folder is changed. for e.g. if your username is admin then in new jenkins the folder would be something like $JENKINS_HOME/users/admin_6635238516816951048/ instead of $JENKINS_HOME/users/admin/ and this mapping is captured separately in a file
$JENKINS_HOME/users/users.xml where a sample entry would look like
<entry>
<string>admin_6635238516816951048</string>
<string>admin_6635238516816951048</string>
</entry>
Here the first String is your username and second is the folder where config.xml for your user should exists.
In our old jenkins this folder structure is not available and hence we see the error
java.nio.file.DirectoryNotEmptyException: /Users/jenkins/<username>
So, what are the steps to migrate users properly so existing credentials can be used.
Once the new jenkins war is deployed on the new jenkins, stop the jenkins.
If there exists a users.xml file in $JENKINS_HOME/users/users.xml, delete it or rename it so jenkins wont look for the new folder structure
Restore your users folder from old jenkins to new jenkins at $JENKINS_HOME location. So all your users should appear in new jenkins # $JENKINS_HOME/users folder
Start the jenkins service.
And you should be able to login with your old jenkins user's credentials.
The detailed explanation can be found at
https://www.jenkins.io/doc/upgrade-guide/2.138/#SECURITY-1072

Related

Jenkins Error: org.xmlpull.v1.XmlPullParserException

I have installed successfully Jenkins after the next day, I have tried to reopen by restarting the Service:Jenkins and got this error.
Should I reinstall Jenkins ?
Thank you.
To get rid of the lockout follow these steps to manually change the version, which could just be back to your old working version.
Stop the Jenkins windows service
Rename war directory to war.bak
Rename jenkins.war to jenkins.war.bak
Get a new war file from https://updates.jenkins.io/download/war/
Copy new jenkins.war into jenkins directory
Start Jenkins windows service
Observe creation of war directory which will now contain contents of jenkins.war archive
Navigate to jenkins home page, at which point you will be informed
that Jenkins is preparing your installation
Once complete, test your
existing jobs to verify compatability
Navigate to 'Manage Jenkins'
via the menu and Action any notifications displayed - plugins, data
format conversions etc.
Delete jenkins.war.bak file and war.bak folder
After following those steps you will be able to get back into Jenkins, you might have other version issues with plug-ins but at least you can get back in and not lose everything. Also always put your pipeline scripts in source control and use a back up plug in for Jenkins.

Jenkins Service vs Jenkins Jar File Permission

I have Jenkins 1.6 installed as a service on a CentOS machine.
At some point in the past the service stopped/crashed/? and Jenkins was restarted from the command line, java -jar jenkins.war, as the root user.
While it was running as root some plugins were updates/installed, and jobs created created/ran. Any new files created are now owned by the root user/group and not by the jenkins user/group.
Meaning, when the service was restarted Jenkins could not read these files. Resulting in plugins not running and most jobs not being loaded.
Manually restoring the permissions(chown, chgrp) to the plugins solves the plugin related issues.
For the jobs it's easy to spot new ones and fix them. Any existing ones that were re run and created new files are more difficult to find.
Then there may be other files which the Jenkins server created, not as part of a job or plugin which need to be changed. The errors are not always obvious, and crop up slowly over time.
Am I better adding the jenkins user to the root group? could this cause issues?
Or manually changing the permissions, hope i got them all! And fix others that come up?
Any suggestions appreciated.
In the end we manually changed the file permissions back to Jenkins. There were some immediate jobs that failed in the following days. And a few which only came up a few months later.
For the most part it worked well.

Exporting Jenkins exact settings / plugins from server 1 to server 2

I read about archiving JENKINS_HOME in the wiki
(https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins)
but didnt exactly tell me how to archive it, was looking for any type of assistance
I found this
How to move Jenkins from one PC to another?
which is great but have some open ended questions and cant comment due to my low rank.
thanks!
You just have to zip your Jenkins home folder and copy it to the new server (the new Jenkins instance must be stopped).
Next, starts the new Jenkins instance and check you can access the new URL.
Once Jenkins is started, go to the Manage Jenkins/Configure system menu and update the Jenkins URL:
It should be enough to move your Jenkins stuff to the new server.

How to automatically login to Jenkins on Active Directory?

I have an Active Directory plugin installed that allows logging in to Jenkins portal with my directory credentials by typing them in on the Login page.
But is there a way to automatically log in users if they are on a domain-joined machine? (Obviously, given the browser is configured to allow providing credentials to the site.)
There's a thread on Jenkins Dev group in which a guy mentions that he developed an SSO plugin that worked for him on Windows. He posted it on GitHub under name NegotiateSSO.
First you need to build it to get the hpi file. (Clone the project to your machine, cd into the directory and run mvn (Maven) in it).
The problem is that when I tried to install it, it broke my Jenkins configuration section/page. There's an exception happening inside the plugin that breaks the entire page.
So it didn't work for me, but hopefully it will get fixed at some point and we'll be able to use it.

All Jenkins plugins are lost when migrating to new Jenkins Server

I have a jenkins server version 1.584 which has at least 50 plugins.
I wanted to check whether i can do an update for the jenkins core, and I didn't want to do it on the original server. Therefore I copied all the folders (expect the builds and modules folders that were under jobs folder) and then started jenkins.
Now it looks like i have no plugin installed at all.
Hope to hear about some way to handle it...
Thanks.
Did you copy the plugins folder to the new Jenkins home ?
It should work.
Did you also copy those *.xml configuration files from your_old_server_jenkins_home/* into your_new_server_jenkins_home/* ?

Resources