How to get a list of installed Jenkins plugins with name and version pair

JenkinsJenkins Plugins

Jenkins Problem Overview


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?

Jenkins Solutions


Solution 1 - Jenkins

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

Screenshot of the Script Console

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):

SScreenshot of script output

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)

Solution 2 - Jenkins

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

Solution 3 - Jenkins

Jenkins 1.588 (2nd of November, 2014) & 1.647 (4th of February, 2016)

  • Jenkins > Manage Jenkins

enter image description here

  • System Information

enter image description here

  • Plugins

enter image description here

Solution 4 - Jenkins

The Jenkins CLI supports listing all installed plugins:

java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins

Solution 5 - Jenkins

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.

Solution 6 - Jenkins

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:

  1. This version is useful for getting specific package version
Jenkins.instance.pluginManager.plugins.each{
  plugin -> 
    println ("${plugin.getShortName()}:${plugin.getVersion()}")
}
  1. If you only want the plugin with the latest version you can use this (thanks @KymikoLoco for the tip)
Jenkins.instance.pluginManager.plugins.each{
  plugin -> 
    println ("${plugin.getShortName()}:latest")
}

Solution 7 - Jenkins

The answers here were somewhat incomplete. And I had to compile information from other sources to actually acquire the plugin list.

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 for parsing (thanks to malenkiy_scot)

Save the following as plugins.groovy.

def plugins = jenkins.model.Jenkins.instance.getPluginManager().getPlugins()
plugins.each {println "${it.getShortName()}: ${it.getVersion()}"}

3. Call the Jenkins API for plugin results

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

Solution 8 - Jenkins

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

Solution 9 - Jenkins

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.

Solution 10 - Jenkins

If you are a Jenkins administrator you can use the Jenkins system information page:

http://<jenkinsurl>/systemInfo

Solution 11 - Jenkins

From the Jenkins home page:

  1. Click Manage Jenkins.
  2. Click Manage Plugins.
  3. Click on the Installed tab.

Or

  1. Go to the Jenkins URL directly: {Your Jenkins base URL}/pluginManager/installed

Solution 12 - Jenkins

Sharing another option found here with credentials

JENKINS_HOST=username:password@myhost.com: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/ /:/'

Solution 13 - Jenkins

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

Solution 14 - Jenkins

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)

Solution 15 - Jenkins

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

Solution 16 - Jenkins

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()}"}

Solution 17 - Jenkins

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

Solution 18 - Jenkins

# 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}")
	}

Solution 19 - Jenkins

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`

Solution 20 - Jenkins

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 UsersSelect UserAPI 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
##############

Solution 21 - Jenkins

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

Solution 22 - Jenkins

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1284795View Question on Stackoverflow
Solution 1 - JenkinsBeheView Answer on Stackoverflow
Solution 2 - JenkinsdbaileyView Answer on Stackoverflow
Solution 3 - JenkinsROMANIA_engineerView Answer on Stackoverflow
Solution 4 - JenkinswmliView Answer on Stackoverflow
Solution 5 - Jenkinsmalenkiy_scotView Answer on Stackoverflow
Solution 6 - Jenkinsjaval88View Answer on Stackoverflow
Solution 7 - JenkinsnoqcksView Answer on Stackoverflow
Solution 8 - JenkinsAndrzej RehmannView Answer on Stackoverflow
Solution 9 - JenkinsAlessoView Answer on Stackoverflow
Solution 10 - JenkinsAndy GView Answer on Stackoverflow
Solution 11 - JenkinsJames LawrukView Answer on Stackoverflow
Solution 12 - JenkinsvishnuView Answer on Stackoverflow
Solution 13 - JenkinsKevin BrotckeView Answer on Stackoverflow
Solution 14 - JenkinsTidhar Klein OrbachView Answer on Stackoverflow
Solution 15 - JenkinshhonyView Answer on Stackoverflow
Solution 16 - Jenkinsuser128364View Answer on Stackoverflow
Solution 17 - JenkinsWojciech SciesinskiView Answer on Stackoverflow
Solution 18 - JenkinsBrianView Answer on Stackoverflow
Solution 19 - JenkinsHuluvu424242View Answer on Stackoverflow
Solution 20 - Jenkinsgdd1984View Answer on Stackoverflow
Solution 21 - JenkinsJesse BrandeburgView Answer on Stackoverflow
Solution 22 - JenkinstsunaView Answer on Stackoverflow