Not to take away from @vaporwave_sailor or @Alex, answers, but to add to..
The basic answer is you MUST upgrade all the compatible plugins you can, then the war, then the newer plugins. All plugins depend on a minimum Jenkins version and the Update Centre will give you different information back.
A further clarification, especially if migrating from < 2.263.4 to > 2.277.1 and many breaking UI changes and tables-divs-regaression (Dashboard): You should ensure your plugins are at the latest version, compatible with the existing Jenkins core version before starting. So, it's plugins, war, plugins.
If you don't upgrade often, use the LTS version. READ the Upgrade Guide. READ the Changelog. Re-READ the Upgrade Guide. Do the same for all your core plugins. There are significant changes, especially around security which may require modifications on your part. Many previously bundled are no longer bundled. Long unsupported plugins may have better alternatives or contain security issues you should be aware of. Behaviors and settings may change.
The following are NOT exact steps, rather things to do in the process. Descriptive, not prescriptive.
Consider installing the Jenkins Configuration as Code (JCasC) plugin to your existing installation first. That will generally let you export almost your entire configuration and simply reload into a new instance. Much easier, but does not handle plugins. For now rip a solution from docker/install_plugins.sh for local use; see Preinstalling Plugins.
Take a backup of your existing Jenkins and install install a "Dev" location. Validate your upgrade there before applying to Prod. ALWAYS. (Also, regularly backup your Prod anyway).
Split the backup in two parts, the system configuration and the jobs. Jobs are in ${JENKINS_HOME}/jobs. The system configuration includes (in ${JENKINS_HOME}
), ./*.xml ./secret.key* ./secrets ./security-tokens ./nodes
, possibly others.
Back to the plugins for a minute. I agree w/adding them in segments:
- Authentication plugins
- Presentation plugins (eg:Active-directory, credentials)
- SCM plugins (eg: Git)
- Adminstrative plugins (eg: greenballs, windows-slaves)
- Tools plugins (eg: ant, maven-plugin)
- Pipeline plugins (eg: workflow-aggregator, Blue-Ocean, K8s)
All the above are "Global plugins, with Configurations"
- Finally, job step plugins; these are job specific.
If using the install_plugins.sh approach, you only need worry about the highest level plugin as it will pull the dependencies. If you install blueocean, it installs some 25 plugins. Just specify the first and you get the rest. Bear in mind, install_plugins.sh is dynamic, in that it gets the available dependencies at the time. So, we decide on the top list, manage that, run once to get the complete list, then read the validated explicit list into the Prod instance (manage the short one, use the complete one, save both). We manage 55 top-level plugins, but there are 160 installed including all dependencies in the full list.
This groovy script will get you your existing plugins:
Jenkins.instance.pluginManager.plugins.sort(false) { a, b -> a.getShortName().toLowerCase() <=> b.getShortName().toLowerCase()}.each { plugin ->
println "${plugin.getShortName()}:${plugin.getVersion()} | ${plugin.getDisplayName()} "
}
// the following may also be useful
// println "+++ ${plugin.getDependants()}"
// println "... ${plugin.getDependencies()"
In the Dev instance, install the war, install the plugins, create a file ${JENKINS_HOME}/init.groovy
, add the line:
Hudson.instance.doQuietDown();
. That lets your system start without letting any jobs start. That way you can examine the system logs w/o panicking or getting confused. Look at everything before INFO: Jenkins is fully up and running
.
Now, you can install the system configurations, but not the ./jobs
and not the ./nodes
. Start it up and check the logs for information, warning alerts and errors.
You might even want to start with your existing war version and existing plugins and basic config, fire that up and save the logs as references. Then, using the UI, upgrade the war, then restart, then the plugins using the UI, then restart, then check and save the logs as references.
If using JCasC, you may go w/a slim install of the configurations,then import your JCasC configurations. JCasC usage here.
*NB: You will notice one major change is more plugins are moving to their own xml configuration instead of adding to the master config.xml. There are many plugins especially that say this configuration is NOT backward compatible. You would have to restore the old config when "downgrading" (correct language - start again from step 1)
Only once your core system starts fine, then I would add the jobs (with QuietDown()
in place ), no nodes and in QuiteDown. Start up again, examine logs for errors, upgrade warnings, etc. Deal w/those. Many plugins will change their data format, hence the many warnings you see, and the "Manage Old Data". IF you're truly paranoid, you may even write a little groovy script that finds all your jobs and re-saves them. While Jenkins knows of the configuration changes, it does not actually change and update the plugin references in the jobs until the job is run or saved (if you need a script, ask a separate question).
Shutdown, delete the jobs directory (this is your DEV instance, so you are OK).
Startup up again and create a small set of validation jobs. These validate all the steps of your real jobs but without impacting them. They are the "test cases" @Alex refers to. We use "sampleApps" of different flavors we have and jobs that cover all the steps. We have test jobs that just get on a node, dump the environment, jobs that clone a repo and build (in the flavors), one that does the whole cycle: clone, build analyze, test, deploy, as well as pipeline jobs (phased). You can now add the nodes configuration and startup and execute those. They are your validation. If they work, then you are as prepared as you can be. You can now export the JCasC configuration as well.
Now, delete the entire Dev instance and REDO using only your finalized configuration and steps as you documented. Did everything work as expected? Run JCasC again, did they match?
Now you can apply the same finalized configuration to your Prod. Shutdown Production and TAKE ANOTHER BACKUP. I'd add the QuietDown()
first to Prod.
Finally, consider taking advantage of some new "System Properties". You can now set locations outside of ${JENKINS_HOME} for jenkins.model.Jenkins.buildsDir
(ps: sym-links in builds are now optional) and jenkins.model.Jenkins.workspacesDir
, removing useless data from the ${JENKINS_HOME}. Your backups will be smaller and simpler and your system performacne may improve! You'll also want to set jenkins.install.runSetupWizard
to false.
Remember, this is descriptive, not preservative. Tailor to your own needs and risk tolerance.