Manage Jenkins Plugins from CLI: Commands and Examples
You can manage Jenkins plugins from the command line using the
jenkins-cli.jar tool with commands like install-plugin, list-plugins, and uninstall-plugin. First, download the CLI jar from your Jenkins server, then run commands to install, update, or remove plugins remotely.Syntax
The Jenkins CLI uses the jenkins-cli.jar file to run commands. The basic syntax to manage plugins is:
java -jar jenkins-cli.jar -s http://your-jenkins-url command [options]- Common commands for plugins include
install-plugin,list-plugins, anduninstall-plugin. - Use
-sto specify your Jenkins server URL. - You may need to provide authentication with
--usernameand--passwordor API token.
bash
java -jar jenkins-cli.jar -s http://your-jenkins-url install-plugin plugin-name java -jar jenkins-cli.jar -s http://your-jenkins-url list-plugins java -jar jenkins-cli.jar -s http://your-jenkins-url uninstall-plugin plugin-name
Example
This example shows how to install the git plugin, list all installed plugins, and then uninstall the git plugin using Jenkins CLI.
bash
wget http://your-jenkins-url/jnlpJars/jenkins-cli.jar java -jar jenkins-cli.jar -s http://your-jenkins-url install-plugin git java -jar jenkins-cli.jar -s http://your-jenkins-url list-plugins java -jar jenkins-cli.jar -s http://your-jenkins-url uninstall-plugin git
Output
Installing git plugin...
Plugin git installed successfully.
Installed plugins:
git 4.11.3
workflow-aggregator 2.6
...
Uninstalling git plugin...
Plugin git uninstalled successfully.
Common Pitfalls
- Not downloading the
jenkins-cli.jarfrom your Jenkins server URL causes connection errors. - For secured Jenkins, missing authentication flags (
--usernameand--passwordor API token) will fail commands. - Trying to install plugins without restarting Jenkins may cause plugins not to load properly.
- Uninstalling plugins that are dependencies for others can break Jenkins.
bash
java -jar jenkins-cli.jar -s http://your-jenkins-url install-plugin git # Wrong: No authentication on secured Jenkins java -jar jenkins-cli.jar -s http://your-jenkins-url --username admin --password yourtoken install-plugin git # Right: Provide authentication
Quick Reference
| Command | Description | Example |
|---|---|---|
| install-plugin | Installs a plugin by name | java -jar jenkins-cli.jar -s URL install-plugin git |
| list-plugins | Lists all installed plugins | java -jar jenkins-cli.jar -s URL list-plugins |
| uninstall-plugin | Removes a plugin by name | java -jar jenkins-cli.jar -s URL uninstall-plugin git |
| safe-restart | Restarts Jenkins safely to apply plugin changes | java -jar jenkins-cli.jar -s URL safe-restart |
Key Takeaways
Use the jenkins-cli.jar tool with commands like install-plugin and list-plugins to manage plugins from CLI.
Always download jenkins-cli.jar from your Jenkins server URL to ensure compatibility.
Provide authentication when Jenkins security is enabled to avoid command failures.
Restart Jenkins after installing or uninstalling plugins to apply changes.
Avoid uninstalling plugins that other plugins depend on to prevent system issues.