skip to content
blog.metters.dev

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

  1. Navigate to the plugin directory
  2. Download plugin
  3. Installation
  4. (Re)start Jenkins

If there are plugins installed, this directory should contain a *.jpi-file for each one of them.

Terminal window
cd /var/lib/docker/volumes/jenkins/_data/plugins

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

Terminal window
cd ~/.jenkins/plugins

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!).

Terminal window
wget https://updates.jenkins.io/download/plugins/cloudbees-folder/6.722.v8165b_a_cf25e9/cloudbees-folder.hpi

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:

Terminal window
docker stop jenkins # `jenkins` or whatever your Docker instance of jenkins is named

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:

Terminal window
mv cloudbees-folder.jpi cloudbees-folder.bak

Rename downloaded plugin

This steps ‘installs’ the previously downloaded plugin. Simply rename the *.hpi-file to *.jpi:

Terminal window
mv cloudbees-folder.hpi cloudbees-folder.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:

Terminal window
chown -R jenkins:jenkins /var/lib/docker/volumes/jenkins/_data/plugins

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:

Terminal window
# if the container was shut down before
docker start jenkins
# if the container was still running
# also, this starts the container if it was shut down
docker restart jenkins

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

Footnotes

  1. I appreciate you bringing this oversight of mine to my attention, Nina!