How to manually roll back Jenkins plugins from command line
/ 3 min read
Let’s say, for some reason Jenkins CLI is not installed or set up. There still is a web UI to manually install/uninstall Jenkins plugins, right? However, this only works if Jenkins is up and running properly. After installing a plugin that lets Jenkins crash, this way is not an option. The rollback must be done manually via command line.
To clarify, the recommended way to manage Jenkins plugins is the web UI, followed by using the Jenkins CLI. Only if those two are unavailable, I would manage plugins the way described below.
Tl;DR
Navigate to the plugin directory
If there are plugins installed, this directory should contain a *.jpi
-file for each one of them.
This assumes you are running Jenkins via Docker. If you are running Jenkins natively on Linux you might want to check out this comment on stackoverflow. On Linux the location should be
Download the plugin
First, you need to download the plugin via command line. For this example we want to install the Folders
-plugin in a specific version (for example, because more a more recent version causes Jenkins to crash). In your browser, navigate to the overview of releases and copy the ‘direct link’ to download the released version, e.g. click here (downloads a file!).
Installation
The ‘installation’ happens by letting the plugin-file having the correct filename extension. I am sure this also works while Jenkins is running. Nevertheless, before mingling with those files, it is better to shutdown the Jenkins instance:
Rename current plugin
Instead of simply deleting the running plugin, I recommend renaming it. Cleanup can still be done at the end. Rename the plugin-file—for example by changing the filename extension to *.bak
:
Rename downloaded plugin
This steps ‘installs’ the previously downloaded plugin. Simply rename the *.hpi
-file to *.jpi
:
Update permissions
Before restarting Jenkins, ensure that the ownership of the plugin files is set correctly. You can do this by running the following command:
If the ownership is not correct, Jenkins may not recognize the newly installed or rolled back plugin.1
(Re)Start Jenkins
Now Jenkins can be booted:
Some key points
- Installing a plugin is done by adding the
*.jpi
file into the plugins folder - Uninstalling a plugin is done by deleting the
*.jpi
file in the plugins-folder (or editing the filename extension) - Downloaded plugin files are just a jar file that follows a certain set of conventions, having the extension
*.hpi
. Installed plugins are identical, having the extension*.jpi
. - I believe, the web UI is doing the very same as described above: it stores the
*.hpi
-file as*.jpi
-file in the plugins-folder (overwriting an already existing one, if necessary)
Additional resources
- It is always a good idea to consult the official documentation: jenkins.io#managing-plugins
- A step-by-step manual with illustrations on how to install and uninstall Jenkins plugins using the UI
- More about
*.hpi
-files
Footnotes
-
I appreciate you bringing this oversight of mine to my attention, Nina! ↩