How can I get a list of installed Jenkins plugins?
I searched the Jenkins Remote Access API document, but it was not found. Should I use Jenkins' CLI? Is there a document or example?
You can retrieve the information using the Jenkins Script Console which is accessible by visiting http://<jenkins-url>/script
. (Given that you are logged in and have the required permissions).
Enter the following Groovy script to iterate over the installed plugins and print out the relevant information:
Jenkins.instance.pluginManager.plugins.each{
plugin ->
println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")
}
It will print the results list like this (clipped):
This solutions is similar to one of the answers above in that it uses Groovy, but here we are using the script console instead. The script console is extremely helpful when using Jenkins.
Update
If you prefer a sorted list, you can call this sort
method:
def pluginList = new ArrayList(Jenkins.instance.pluginManager.plugins)
pluginList.sort { it.getShortName() }.each{
plugin ->
println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")
}
Adjust the Closure to your liking (e.g. here it is sorted by the shortName, in the example it is sorted by DisplayName)
Jenkins.instance.pluginManager.plugins.sort({it.getDisplayName()}).each{ plugin -> println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}") }
echo 'script=Jenkins.instance.pluginManager.plugins.each{ plugin -> println ("${plugin.getShortName()}:${plugin.getVersion()}") } null' \ | no_proxy=localhost curl --netrc --silent --data-binary @- -X POST "http://localhost:8080/jenkins/scriptText" | sort > plugins.txt
jenkins.model.Jenkins.instance.getPluginManager().getPlugins().stream().sorted().each { println "${it.getShortName()} | ${it.getVersion()} | ${it.getDisplayName()}" }
Commented
Dec 19, 2018 at 8:22
These days I use the same approach as the answer described by @Behe below instead, updated link: https://stackoverflow.com/a/35292719/3423146 (old link: https://stackoverflow.com/a/35292719/1597808)
You can use the API in combination with depth, XPath, and wrapper arguments.
The following will query the API of the pluginManager to list all plugins installed, but only to return their shortName and version attributes. You can of course retrieve additional fields by adding '|' to the end of the XPath parameter and specifying the pattern to identify the node.
wget http://<jenkins>/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins
The wrapper argument is required in this case, because it's returning more than one node as part of the result, both in that it is matching multiple fields with the XPath and multiple plugin nodes.
It's probably useful to use the following URL in a browser to see what information on the plugins is available and then decide what you want to limit using XPath:
http://<jenkins>/pluginManager/api/xml?depth=1
curl 'http://192.168.197.133:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins' | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'
Commented
Dec 22, 2014 at 1:08
curl -s -k "http://jenkins/pluginManager/api/json?depth=1" | jq '.plugins[]|{shortName, version,longName}' -c
curl -s "http://<jenkins>/pluginManager/api/json?depth=1&tree=plugins\[shortName,version,longName\]"
Jenkins 1.588 (2nd of November, 2014) & 1.647 (4th of February, 2016)
The Jenkins CLI supports listing all installed plugins:
java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins
list-plugins
CLI command does not require the user to have the Overall/RunScripts permission as groovy
command does.
Commented
Dec 12, 2017 at 15:14
If you're working in a docker environment and want to output the plugin list in a plugins.txt format in order to pass that to the install_scripts.sh use these scripts in the http://{jenkins}/script
console:
Jenkins.instance.pluginManager.plugins.each{
plugin ->
println ("${plugin.getShortName()}:${plugin.getVersion()}")
}
Jenkins.instance.pluginManager.plugins.each{
plugin ->
println ("${plugin.getShortName()}:latest")
}
:latest
to the end: println ("${plugin.getShortName()}:latest")
Commented
Oct 23, 2019 at 0:11
Use Jenkins CLI like this:
java -jar jenkins-cli.jar -s http://[jenkins_server] groovy = < pluginEnumerator.groovy
=
in the call means 'read from standard input'. pluginEnumerator.groovy contains the following Groovy code:
println "Running plugin enumerator"
println ""
def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
plugins.each {println "${it.getShortName()} - ${it.getVersion()}"}
println ""
println "Total number of plugins: ${plugins.size()}"
If you would like to play with the code, here's Jenkins Java API documentation.
isActive()
api that you can use in the groovy script in this answer to get the state of the plugin. See javadoc.jenkins-ci.org/hudson/PluginWrapper.html#isActive().
The answers here were somewhat incomplete. And I had to compile information from other sources to actually acquire the plugin list.
The Jenkins CLI will allow us to interact with our Jenkins server from the command line. We can get it with a simple curl call.
curl 'localhost:8080/jnlpJars/jenkins-cli.jar' > jenkins-cli.jar
Save the following as plugins.groovy
.
def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
plugins.each {println "${it.getShortName()}: ${it.getVersion()}"}
Call the Jenkins server (localhost:8080
here) with your login username and password while referencing the Groovy script:
java -jar jenkins-cli.jar -s http://localhost:8080 groovy --username "admin" --password "admin" = < plugins.groovy > plugins.txt
The output to plugins.txt looks like this:
ace-editor: 1.1
ant: 1.5
antisamy-markup-formatter: 1.5
authentication-tokens: 1.3
blueocean-autofavorite: 1.0.0
blueocean-commons: 1.1.4
blueocean-config: 1.1.4
blueocean-dashboard: 1.1.4
blueocean-display-url: 2.0
blueocean-events: 1.1.4
blueocean-git-pipeline: 1.1.4
blueocean-github-pipeline: 1.1.4
blueocean-i18n: 1.1.4
blueocean-jwt: 1.1.4
blueocean-personalization: 1.1.4
blueocean-pipeline-api-impl: 1.1.4
blueocean-pipeline-editor: 0.2.0
blueocean-pipeline-scm-api: 1.1.4
blueocean-rest-impl: 1.1.4
With curl
and jq
:
curl -s <jenkins_url>/pluginManager/api/json?depth=1 \
| jq -r '.plugins[] | "\(.shortName):\(.version)"' \
| sort
This command gives output in a format used by special Jenkins plugins.txt
file which enables you to pre-install dependencies (e.g. in a docker image):
ace-editor:1.1
ant:1.8
apache-httpcomponents-client-4-api:4.5.5-3.0
Example of a plugins.txt
: https://github.com/hoto/jenkinsfile-examples/blob/master/source/jenkins/usr/share/jenkins/plugins.txt
Behe's answer with sorting plugins did not work on my Jenkins machine. I received the error java.lang.UnsupportedOperationException
due to trying to sort an immutable collection i.e. Jenkins.instance.pluginManager.plugins
. Simple fix for the code:
List<String> jenkinsPlugins = new ArrayList<String>(Jenkins.instance.pluginManager.plugins);
jenkinsPlugins.sort { it.displayName }
.each { plugin ->
println ("${plugin.shortName}:${plugin.version}")
}
Use the http://<jenkins-url>/script
URL to run the code.
displayName
while printing out the shortName
, this was very confusing as some plugins aren't alphabetically the same for both, and it results in a list that doesn't appear sorted. Changing it.displayName
to it.shortName
solves this nicely.
Commented
Oct 19, 2018 at 16:35
If you are a Jenkins administrator you can use the Jenkins system information page:
http://<jenkinsurl>/systemInfo
http://localhost:8080/systemInfo
--some servers are case-sensitive. Note also that it requires the currently logged in user to have Overall/Administer permission.
Sharing another option found here with credentials
JENKINS_HOST=username:[email protected]:port
curl -sSL "http://$JENKINS_HOST/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'|sed 's/ /:/'
curl -sSL "http://127.0.0.1:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \n/g' | sort
From the Jenkins home page:
Or
I wanted a solution that could run on master without any auth requirements and didn't see it here. I made a quick bash script that will pull out all the versions from the plugins dir.
if [ -f $JENKINS_HOME/plugin_versions.txt ]; then
rm $JENKINS_HOME/plugin_versions.txt
fi
for dir in $JENKINS_HOME/plugins/*/; do
dir=${dir%*/}
dir=${dir##*/}
version=$(grep Plugin-Version $JENKINS_HOME/plugins/$dir/META-INF/MANIFEST.MF | awk -F': ' '{print $2}')
echo $dir $version >> $JENKINS_HOME/plugin_versions.txt
done
grep Plugin-Version */META-INF/MANIFEST.MF | sed -e 's!/META-INF/MANIFEST.MF:Plugin-Version: !:!g' > ../plugins2.txt
Commented
Apr 2, 2020 at 13:38
Another option for Python users:
from jenkinsapi.jenkins import Jenkins
#get the server instance
jenkins_url = 'http://<jenkins-hostname>:<jenkins-port>/jenkins'
server = Jenkins(jenkins_url, username = '<user>', password = '<password>')
#get the installed plugins as list and print the pairs
plugins_dictionary = server.get_plugins().get_plugins_dict()
for key, value in plugins_dictionary.iteritems():
print "Plugin name: %s, version: %s" %(key, value.version)
I think these are not good enough answer(s)... many involve a couple of extra under-the-hood steps. Here's how I did it.
sudo apt-get install jq
...because the JSON output needs to be consumed after you call the API.
#!/bin/bash
server_addr = 'jenkins'
server_port = '8080'
curl -s -k "http://${server_addr}:${server_port}/pluginManager/api/json?depth=1" \
| jq '.plugins[]|{shortName, version,longName,url}' -c | sort \
> plugin-list
echo "dude, here's your list: "
cat plugin-list
There are lots of way to fetch this information but I am writing two ways as below : -
1. Get the jenkins cli.
The jenkins CLI will allow us to interact with our jenkins server from the command line. We can get it with a simple curl call.
curl 'localhost:8080/jnlpJars/jenkins-cli.jar' > jenkins-cli.jar
2. Create a groovy script. OR from jenkins script console
We need to create a groovy script to parse the information we receive from the jenkins API. This will output each plugin with its version. Save the following as plugins.groovy.
def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
plugins.each {println "${it.getShortName()}: ${it.getVersion()}"}
You can be also interested what updates are available for plugins. For that, you have to merge the data about installed plugins with information about updates available here https://updates.jenkins.io/current/update-center.json .
To parse the downloaded file as a JSON you have to read online the second line (which is huge).
# list of plugins in sorted order
# Copy this into your Jenkins script console
def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
List<String> list = new ArrayList<String>()
i = 0
plugins.each {
++i
//println " ${i} ${it.getShortName()}: ${it.getVersion()}"
list.add("${it.getShortName()}: ${it.getVersion()}")
}
list.sort{it}
i = 0
for (String item : list) {
i++
println(" ${i} ${item}")
}
If Jenkins run in a the Jenkins Docker container you can use this command line in Bash:
java -jar /var/jenkins_home/war/WEB-INF/jenkins-cli.jar -s http://localhost:8080/ list-plugins --username admin --password `/bin/cat /var/jenkins_home/secrets/initialAdminPassword`
For Jenkins version 2.125 the following worked.
NOTE: Replace sections that say USERNAME and APIKEY with a valid UserName and APIKey for that corresponding user. The API key for a user is available via Manage Users → Select User → API Key option.
You may have to extend the sleep if your Jenkins installation takes longer to start.
The initiation yum update -y
will upgrade the version as well if you installed Jenkins using yum as well.
#JENKINS AUTO UPDATE SCRIPT link this script into a cron
##############
!/bin/bash
sudo yum update -y
sleep 120
UPDATE_LIST=$( sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ list-plugins | grep -e ')$' | awk '{ print $1 }' );
if [ ! -z "${UPDATE_LIST}" ]; then
echo Updating Jenkins Plugins: ${UPDATE_LIST};
sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ install-plugin ${UPDATE_LIST};
sudo /usr/bin/java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -auth [USERNAME:APIKEY] -s http://localhost:8080/ safe-restart;
fi
##############
I'm a little surprised this wasn't mentioned here, but the pluginusage URL from the https://plugins.jenkins.io/plugin-usage-plugin/ seems pretty nice and is available to regular users, no admin needed (just to install the plugin). Good to use to check if the Jenkins server you're using has a particular plugin:
http://<jenkinsurl>/pluginusage
If you have access to Master Server its quite simple. All you have to do is to go to Jenkins directory inside that you will find plugins folder, It contains all the list and data you need.
In my case it is at /var/lib/jenkins/plugins
There is a table listing all the plugins installed and whether or not they are enabled at http://jenkins/systemInfo
However, you need administrative rights for this.