Optimizing Jenkins Plugin Management with CLI – Setup, Benefits, and Best Practices

favxlaw

Favour Lawrence

Posted on October 28, 2024

Optimizing Jenkins Plugin Management with CLI – Setup, Benefits, and Best Practices

You're in the thick of CI/CD action, and you're relying on Jenkins to run your automation like a well-oiled machine. But plugin management becomes a question of control and efficiency: stick with the tried-and-true web interface, or harness the power of the CLI? . Maybe you’re juggling multiple builds, or you’re trying to keep things speedy without hiccups. Whatever the case, you’re wondering if there’s a better way to manage Jenkins plugins.

If you’re like me and need to keep things consistent across servers, the CLI could be the tool you didn’t know you needed. By the end of this guide, you’ll see why Jenkins CLI is a go-to for streamlined plugin management in CI/CD pipelines, giving you control and efficiency at every step.

Jenkins CLI vs. Web Interface for Managing Plugins

Managing Jenkins plugins can feel straightforward in the web interface. Everything is visual: you can click to install, update, or uninstall plugins with ease. This simplicity is why many start with the web UI—it’s intuitive, and the visual feedback is satisfying. But as Jenkins environments grow in complexity, the web approach starts to show limitations. Let’s look at some common scenarios to see how each method performs.

Scenario 1: Bulk Plugin Management Across Multiple Projects
You’re the Jenkins wrangler, herding multiple builds and projects simultaneously. Now imagine each build needing a plugin update or configuration tweak. In the web interface, you’re stuck clicking around, opening tabs, and repeating the same steps over and over. It's a lot like trying to dig a trench with a spoon: frustrating and ineffective.
The Jenkins CLI, however, lets you automate this process with scripts. A few simple commands and your builds are updated, in sync, and ready to roll—no tab-hopping necessary.
Have you ever had to perform the same plugin management steps over and over? The CLI can make this repetitive work a thing of the past.

Scenario 2: Downtime and Reliability
One of the biggest challenges when managing plugins is handling updates without disrupting other builds or jobs. With the web interface, a plugin installation or update sometimes disrupts the UI itself, causing timeouts or errors that can delay progress. If something goes wrong mid-installation, the whole interface might hang, leaving you with half-installed plugins or partially completed updates.

The CLI lets you bypass these issues. By directly running commands, you minimize the risk of web UI slowdowns. Jenkins CLI commands provide clearer error messages and logs, helping to quickly identify and resolve issues without risking the entire Jenkins environment. In other words, the CLI keeps downtime to a minimum.

Scenario 3: Scripting and Reproducibility

Reproducible and reliable plugin management is where the Jenkins CLI truly excels. Suppose you need to set up a new Jenkins instance with a specific set of plugins. The web interface would require manual installation for each plugin, which is time-consuming and prone to inconsistencies.
The CLI, however, enables you to automate this process with scripting. By creating a list of required plugins, you can standardize and streamline installation, ensuring that each instance is configured identically.

Example;
Your team is scaling up, and you need to quickly set up multiple Jenkins servers for different projects. Each instance requires a consistent set of plugins (e.g., Git, Pipeline, Docker, Blue Ocean) to maintain standard functionality across projects. Using the web interface, you’d need to manually search for each plugin, install them one-by-one, and repeat this for every instance.

CLI Solution:

  1. Create a Plugins List: Start by listing the plugins you need in a simple text file, plugins.txt. This file contains the plugin IDs and desired versions, like so:
git:4.10.0
pipeline:2.6
docker:1.2
blueocean:1.24.8
Enter fullscreen mode Exit fullscreen mode
  1. Automate the Plugin Installation: With the Jenkins CLI, you can use this plugins.txt to automate installations. Using a shell script or single command, you can loop through each plugin in the file and install it on a new Jenkins instance. Here’s how it works:
# Loop through each plugin in plugins.txt and install it using the CLI
while IFS=: read -r plugin version; do
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth @creds install-plugin "$plugin"@"$version"
done < plugins.txt

Enter fullscreen mode Exit fullscreen mode
  1. Consistency Across Instances: By running this script, you’re ensuring every new Jenkins instance gets set up with the exact same set of plugins. There’s no need to rely on manual clicks or worry about missing a plugin—every installation is scripted, reliable, and consistent.

  2. Verifying Installation: Once all plugins are installed, you can use the CLI to restart Jenkins to complete the installation:

java -jar jenkins-cli.jar -s http://localhost:8080/ -auth @creds safe-restart

Enter fullscreen mode Exit fullscreen mode

Setting Up Jenkins CLI
Getting started with Jenkins CLI is straightforward and lets you tap into Jenkins’ full command-line potential. Instead of diving into the technical details here, you can follow the official Jenkins guide for a clear, step-by-step setup. You’ll find all you need in Jenkins’ documentation:

Set up Jenkins CLI on Jenkins.io

Thanks for reading, would love your contribution or thought on this and yeah this is my first post here...

💖 💪 🙅 🚩
favxlaw
Favour Lawrence

Posted on October 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related