Introduction
Jenkins Plugins play very important role for adding and enhancing the features in Jenkins. Managing Jenkins Plugin is also crucial. In simple term, manage Jenkins plugin carefully and in return you will get awesome functions and features.
In this post, we will learn managing Jenkins plugin from command line and GUI. Because Jenkins is automation server, we tried to bring more command line methods for automation folks.
References
In this post, we will refer the following variables. You have to replace with its correct value wherever we use in this post.
Variable | Value |
---|---|
$JENKINS_URL | The URL of your Jenkins Server. Example: http://192.168.1.1:8080 or https://jenkins.example.com |
$JENKINS_HOME | Absolute path of Jenkins installed directory. Example: /var/lib/jenkins or any custom path you have made. |
$JENKINS_ADMIN_USER | Jenkins user name which has admin privileges. |
$JENKINS_ADMIN_PASSWD | Password of $JENKIN_ADMIN_USERNAME. |
$JENKINS_PLUGIN_URL | Jenkins plugin download URL. |
$JENKINS_PLUGIN_NAME | Jenkins plugin short name. |
Manage Jenkins Plugin
In GUI (Graphical User Interface), managing Jenkins plugin is quite easy. We will also add the cli(command line) which will help you in automation.
GUI Users
The GUI users can reach to plugin page by either directly open the URL $JENKINS_URL/pluginManager/
Or stepwise do click as shown in given below screenshot (“Manage Jenkins >> Manage Plugins“).
Command Line Users
Command line folks, download the jenkins-cli.jar file from your Jenkins Server.
Syntax:wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
##Example wget http://localhost:8080/jnlpJars/jenkins-cli.jar
List Installed Jenkins Plugin – GUI / CLI
Here, we will list the installed Jenkins Plugin from GUI and CLI both.
List Installed Jenkins Plugin From Graphical User Interface (GUI)
In “Manage Plugin” page, click on “Installed” tab. This will show the list of Jenkins Plugin which are installed.
In web browser, quick URL path syntax is $JENKINS_URL/pluginManager/Installed
.
List Installed Jenkins Plugin From Command Line Interface (CLI)
Syntax:java -jar ./jenkins-cli.jar -s "$JENKINS_URL" -auth $JENKINS_ADMIN_USER:$JENKINS_ADMIN_PASSWD -noKeyAuth list-plugins
# Example java -jar ./jenkins-cli.jar -s "http://localhost:8080" -auth admin:admin123 -noKeyAuth list-plugins
List Available Jenkins Plugin For Downloading – GUI / CLI
The ‘Available’ Jenkins plugin meaning is the plugins which are available for downloading and install.
List Available Jenkins Plugin For Downloading From Graphical User Interface (GUI)
In Jenkins ‘Manage Plugin’ page, click on “Available” tab. It will list all the available plugins which you can also install from same tab itself. The given below screenshot is self explanatory itself. Same we are discussing in our next Jenkins plugin installation section.
List Available Jenkins Plugin For Downloading From Command Line Interface (CLI)
You can curl and parse the result.curl http://updates.jenkins-ci.org/download/plugins/
Install Jenkins Plugin – GUI / CLI
In this section we will learn installing the Jenkins Plugin.
Install Jenkins Plugin From Graphical User Interface (GUI)
Through GUI you can install Jenkins by 2 methods.
Method 1. Install Jenkins Plugin from ‘Available’ Tab | GUI
Given below is the order to follow.
- Click on ‘Available’ tab
- Select plugin by clicking checkbox
- As per requirement either click “Install without restart” or “Download now and install after restart”
Method 2. Install Jenkins Plugin manually from ‘Advanced’ Tab | GUI
For this you have to download the package in system and then upload from web console. You can search the plugin from Jenkins Plugin Page .
- Click on ‘Advanced’ tab
- Click on ‘Advanced…’ button (It will expand more options)
- Go to ‘Upload Plugin’ Section >> Choose File >> Upload
- click ‘Submit’ button at the end
Check given below screenshot for uploading plugin from web console.
Install Jenkins Plugin From Command Line Interface (CLI)
You can choose any one one option to install Jenkins plugin through command line.
Note: Here, -restart
will restart the Jenkins service after successful installation of the plugin.
Syntax 1: You should have Jenkins Plugin Download URL. Search the Jenkins plugin from official website and get your plugin URL.java -jar jenkins-cli.jar -s "$JENKINS_URL" -auth admin:admin123 -noKeyAuth install-plugin $JENKINS_PLUGIN_URL -restart
#Example 1: installing Jenkins plugin called git-parameter java -jar ./jenkins-cli.jar -s "http://localhost:8080" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth install-plugin https://plugins.jenkins.io/git-parameter -restart
Syntax 2: You should have Jenkins Plugin short name.java -jar jenkins-cli.jar -s "$JENKINS_URL" -auth admin:admin123 -noKeyAuth install-plugin $JENKINS_PLUGIN_NAME -restart
#Example 2 :Installing Jenkins plugin called git-parameter java -jar ./jenkins-cli.jar -s "http://localhost:8080" -auth admin:admin123 -noKeyAuth install-plugin git-parameter –restart
Uninstall Jenkins Plugin – GUI / CLI
You can easily uninstall the Jenkins Plugin from GUI and CLI both. Currently to uninstall/remove Jenkins from CLI you have login into Jenkins Server and remove the plugin from its installation directory. We have described about the steps in given below sections.
Uninstall Jenkins Plugin From Graphical User Interface (GUI)
Go to Jenkins Manage Plugin page and follow the given below steps to uninstall Jenkins Plugin.
-
- Click on’Installed’ tab,then
- Select Jenkins Plugin to uninstall, then
- Click ‘Uninstall’ button, then
- Click “Yes” button, then
- Restart Jenkins service. for restart you can append ‘restart’ string in JENKINS_URL. Click ‘Yes’ button for confirming the restart.
Syntax:$JENKINS_URL/restart
- You will be logout after Jenkins restart.
Note: After uninstalling the plugin, to take effect you have to restart the Jenkins service.
Uninstall Jenkins Plugin From Command Line Interface (CLI)
To uninstall Jenkins plugin, login to Jenkins server. Change directory to Jenkins plugin path and remove the Jenkins Plugin jpi
extension file and its related folder. This step you have to do after login in Jenkins Server terminal console.
Syntax:cd $JENKINS_HOME/plugins
rm -fr Plugin-Name-DIRECTORY
rm Plugin-Name.jpi
See the given below screenshot carefully for clear understanding. Here, we are uninstalling the Jenkins plugin called ‘git-parameter’.
Restart the Jenkins service after uninstalling the plugin. This step is mandatory.
sudo systemctl restart jenkins
Update Jenkins Plugin – GUI / CLI
It is very important to update Jenkins plugin on regular basis.It is important for security reason and bug fixes done in Jenkins Plugin.
Update Jenkins Plugin From Graphical User Interface (GUI)
In Jenkins Plugin Manager follow the given below steps in a sequence.
-
- Click on ‘Update’ tab.
- Select Check-boxes of Jenkins Plugin which you want to update
- Click on “Download now and install after restart”.
Note: You may have noticed a button labelled as “Check Now”. This is for checking any Jenkins Plugin update is available.
Update Jenkins Plugin From Command Line Interface (CLI)
Updating Jenkins plugin through is 3 steps process (List and install the plugins then restart the Jenkins).
-
- First List the new plugins updates available to update
Syntax:java -jar ./jenkins-cli.jar -s "$JENKINS_URL" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth list-plugins| grep -e ')$'
# Example
java -jar ./jenkins-cli.jar -s "http://localhost:8080" -auth admin:admin123 -noKeyAuth list-plugins| grep -e ') - Now you got the list from above command. Install these plugin from command line.
java -jar jenkins-cli.jar -s "$JENKINS_URL" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth install-plugin $JENKINS_PLUGIN_NAME
# Example
java -jar jenkins-cli.jar -s "http://localhost:8080" -auth admin:admin123 -noKeyAuth install-plugin workflow-support - Do restart the Jenkins once plugins are installed.
Syntax:
java -jar enkins-cli.jar -s "$JENKINS_URL" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth safe-restart;
java -jar enkins-cli.jar -s "http://localhost:8080" -auth admin:admin123 -noKeyAuth safe-restart;
- First List the new plugins updates available to update
Bash Script To Update All Jenkins Plugin
In above section we have already written about all the basic command line steps to update Jenkins plugin. In case you have many Jenkins Plugin to update then you should install it by using script. Here, we will write bash scripting using loop.
Replace the values given in bash script variables.
#!/bin/bash # Author: Sharad Chhetri # Description: Update all Jenkins plugin # Version 1.0 _JENKINS_URL=http://localhost:8080 _JENKINS_USER=admin _JENKINS_PASSWD=admin123 java -jar ./jenkins-cli.jar -s "$_JENKINS_URL" -auth "$_JENKINS_USER:_JENKINS_PASSWD" -noKeyAuth list-plugins| grep -e ')
We hope the Jenkins Plugin Management will be helpful for you. You can use command line for your automation script.
Please do let us know your any kind of feedback to improve this post.
- Now you got the list from above command. Install these plugin from command line.
java -jar jenkins-cli.jar -s "$JENKINS_URL" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth install-plugin $JENKINS_PLUGIN_NAME
- Do restart the Jenkins once plugins are installed.
Syntax:java -jar enkins-cli.jar -s "$JENKINS_URL" -auth JENKINS_ADMIN_USER:JENKINS_ADMIN_PASSWD -noKeyAuth safe-restart;
Praveen says
When I tried to do an update I see an error saying “ERROR:Failed to install plugin mailer”
java -jar jenkins-cli.jar -s URL -auth id:password install-plugin mailer
Installing mailer from update center
ERROR: Failed to install plugin mailer
Please suggest what could be the issue and where can I find the relevant logs.
sunil says
Hi sharad Chhetri ,
am unable to install all plugins its installing only one plugin from the list .
file = $1
while read -r line; do
java -jar jenkins-cli.jar -s “$_JENKINS_URL” -auth “$_JENKINS_USER:$_JENKINS_PASSWD” install-plugin “$line”;
sleep 5
done < plugins.txt
java -jar jenkins-cli.jar -s "$_JENKINS_URL" -auth "$_JENKINS_USER:$_JENKINS_PASSWD" safe-restart;
Michael says
Hi,
thanks for the detailed description and the script!
However, we need to update our own custom plugin, i.e. it is not part of the UpdateCenter. I tried many different way, but non of them worked for me:
– it cannot be referenced via the short name as it is not part of the Update Center
– I didnt find a way to use cli command “install-plugin” to install a local with file:// – it always fails with FileNotFoundException (even though the path seems correct)
– I cannot remove the existing folder of that plugin in JENKINS_HOME\plugins: fails with Access denied (I assume b/c Jenkins process is still using it)
Any idea how to achieve that?
Thanks a lot!
Michael
Eric Dunn says
Hi (running on MacOS)
Works until it hits “| while read _UPDATE_LIST;”
See error.
java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8080/cli?remoting=false
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1913)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1509)
at hudson.cli.FullDuplexHttpStream.(FullDuplexHttpStream.java:101)
at hudson.cli.CLI.plainHttpConnection(CLI.java:668)
at hudson.cli.CLI._main(CLI.java:628)
at hudson.cli.CLI.main(CLI.java:427)
Sharad Chhetri says
Hi Eric,
Which Jenkins version are you using. I suspect it could be old version because Jenkins 2.165 and newer no longer supports the old (-remoting) mode in either the client or server.
(reference: https://jenkins.io/doc/book/managing/cli/#authentication)
Regards
Sharad
Rajasekhar says
“$_JENKINS_USER:$_JENKINS_PASSWD”
Add $ to the _JENKINS_PASSWD variable.
Rajasekhar says
Corrected the script by appending $ to the _JENKINS_PASSWD variable :
#!/bin/bash
# Author: Sharad Chhetri
# Description: Update all Jenkins plugin
# Version 1.0
_JENKINS_URL=http://164.99.177.111:8080/jenkins
_JENKINS_USER=admin
_JENKINS_PASSWD=novell
java -jar ./jenkins-cli.jar -s “$_JENKINS_URL” -auth “$_JENKINS_USER:$_JENKINS_PASSWD” -noKeyAuth list-plugins| grep -e ‘)$’ | awk ‘{ print $1 }’| while read _UPDATE_LIST;
do
java -jar jenkins-cli.jar -s “$_JENKINS_URL” -auth “$_JENKINS_USER:$_JENKINS_PASSWD” -noKeyAuth install-plugin “$_UPDATE_LIST”;
done
java -jar jenkins-cli.jar -s “$_JENKINS_URL” -auth “$_JENKINS_USER:$_JENKINS_PASSWD” -noKeyAuth safe-restart;