173

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?

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
user1284795
  • 1,881
  • 3
  • 13
  • 8

21 Answers21

185

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)

Behe
  • 6,543
  • 3
  • 29
  • 39
  • 3
    Of all the answers, this is the most useful for filing a plugin bug report; it can be done using the standard web UI and gives the result in a format that can be easily pasted into the "Environment" field. – Aaron D. Marasco May 16 '16 at 12:16
  • 8
    Great answer for quickly creating a plugins.txt for docker Jenkins! – Erik Englund Jun 03 '16 at 06:47
  • 1
    It might be useful to add sorting so that the list of plugins is consistent: `Jenkins.instance.pluginManager.plugins.sort({it.getDisplayName()}).each{ plugin -> println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}") }` – wheleph Nov 18 '16 at 13:55
  • Per Allessandro's answer you may need to coerce the List to another type in a new object to sort it. https://stackoverflow.com/a/48198920/3794873 – dragon788 Jan 24 '18 at 21:19
  • 1
    This is the answer we've switched to locally instead of my XPath suggestion above, wrapped with a curl request and some pruning of built from source plugins we use this approach to generate the plugins.txt for our docker image as mentioned by @ErikEnglund above ```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 ``` – dbailey Jul 04 '18 at 14:57
  • 9
    The sort doesn't work, it's an unmodifiableMap these days. Use: ```jenkins.model.Jenkins.instance.getPluginManager().getPlugins().stream().sorted().each { println "${it.getShortName()} | ${it.getVersion()} | ${it.getDisplayName()}" }``` – Ed Randall Dec 19 '18 at 08:22
  • You can further determine which of the "installed" plugins are disabled by inspecting the .isActive() method. E.g. `${it.isActive()}` will be true if the plugin is active, false if it is not enabled. `.isEnabled()` is also interesting because the plugin may be ENABLED but not active meaning it will be loaded the next time jenkins starts, or the configuration is reloaded. – Steven the Easily Amused Nov 27 '20 at 17:44
100

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
dbailey
  • 1,318
  • 1
  • 9
  • 14
  • Hi, Do you know how to get the list of plugins that are actually used by Jenkins jobs and Jenkins system rather than the complete list of installed plugins? Thanks – user1164061 May 09 '14 at 18:46
  • Not straight forward, but http://stackoverflow.com/questions/18138361/how-can-i-know-whether-the-plugin-is-used-by-any-jobs-in-jenkins might be of more use to you. Automatically determining the type of each plugin in order to determine where to look or query jenkins likely requires a good deal of knowledge on the internals of jenkins. But if you are willing to retrieve the list of plugins and create the config file manually or create a mapping of known plugins to type and generate the config file using this, it should do what you want. – dbailey Jun 03 '14 at 17:51
  • 3
    Worked well for me on Mac OS X. I wanted to convert the output to a plain text list, so used some Perl regex to strip the tags: `curl 'http://192.168.197.133:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins' | perl -pe 's/.*?([\w-]+).*?([^)+/\1 \2\n/g'` – G. Lombard Dec 22 '14 at 01:08
  • @dbailey Really useful! Thanks – suryakrupa Sep 11 '15 at 19:08
  • 9
    Alternative in JSON format: `curl -s -k "http://jenkins/pluginManager/api/json?depth=1" | jq '.plugins[]|{shortName, version,longName}' -c` – MarkHu Jan 08 '16 at 18:25
  • Improved JSON curl: `curl -sSL -k "http://jenkins/pluginManager/api/json?depth=1" | jq '.plugins[]|{shortName, version,longName}' -c | sort` (follows 301 redirects, sorted) – MarkHu May 26 '16 at 04:05
  • Alternative in JSON format _without_ jq: `curl -s "http:///pluginManager/api/json?depth=1&tree=plugins\[shortName,version,longName\]"` – Jean Bob Jan 24 '18 at 11:14
  • These days I'd tend to use a curl query to the script console to generate the text output used for my docker container: `echo 'script=Jenkins.instance.pluginManager.plugins.each{ plugin -> println ("${plugin.getShortName()}:${plugin.getVersion()}") }; null' | no_proxy=localhost curl --silent --data-binary @- -X POST \ "http://:@localhost:8080/jenkins/scriptText" \ | sort | grep -v -e " (private.*-root)$" > plugins.txt` – dbailey Jan 26 '18 at 14:09
  • 1
    I believe that this requires administration privileges, but I'm not sure. – mkobit Jan 29 '18 at 22:16
  • 2
    Confirmed that this requires admin privileges per [the 2016-05-11 security advisory](https://jenkins.io/security/advisory/2016-05-11). – mkobit Mar 28 '18 at 19:02
  • Thank you @dbailey. It worked perfectly fine for me. I did this.. open this URL from Browser as our Jenkins is sso enabled. https:///pluginManager/api/xml?depth=1 Saved the xml and then ran this in PowerShell:
    $XPath="/localPluginManager/plugin"
    Select-Xml -Path "C:\workpace\plugin.xml" -XPath $XPath | Select-Object -ExpandProperty Node | Select-Object shortName, version
    
    – Prosenjit Sen Apr 24 '21 at 11:14
31

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

Elrond_EGLDer
  • 47,430
  • 25
  • 189
  • 180
  • 1
    This is very simple, and I am able to get the list from DEV and PRD server, paste them into Excel and compare their versions side by side. – Jirong Hu Jul 04 '16 at 15:53
24

The Jenkins CLI supports listing all installed plugins:

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

wmli
  • 1,390
  • 12
  • 13
22

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.

malenkiy_scot
  • 15,749
  • 6
  • 60
  • 85
  • @user1284795, was this helpful? – malenkiy_scot Apr 17 '12 at 14:19
  • 1
    Hi, do you know how to get the plugins used by Jenkins system and Jenkins job instead of getting all plugins installed? I would like this to help me uninstall all unused plugins. Any help is appreciated. Thanks! – user1164061 May 08 '14 at 23:30
  • This should be the accepted answer. @user1164061, I don't think there is a any difference between plugins visible to a job vs to the server. There is an `isActive()` api that you can use in the groovy script in this answer to get the state of the plugin. See http://javadoc.jenkins-ci.org/hudson/PluginWrapper.html#isActive(). – akhan Mar 03 '15 at 05:48
  • This answer gets my vote to be the accepted answer. – Chris F Nov 07 '20 at 03:48
21

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")
}
Alessandro Lucarini
  • 985
  • 3
  • 13
  • 25
  • 1
    If you want to get the latest versions of all the plugins, you can extend this to only get the short name and add `:latest` to the end: `println ("${plugin.getShortName()}:latest")` – KymikoLoco Oct 23 '19 at 00:11
18

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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
noqcks
  • 463
  • 4
  • 9
  • The above commands should run on your workstation and not on a Jenkins job – psicopante Oct 02 '18 at 17:01
  • The command seems to result in "ERROR: anonymous is missing the Overall/Read permission" in latest versions.. instead passing the auth before worked for me java -jar jenkins-cli.jar -s http://localhost:8080 -auth "admin:" groovy = < plugins.groovy – prasanna Nov 30 '18 at 07:16
13

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

Andrzej Rehmann
  • 8,609
  • 7
  • 34
  • 36
12

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Alesso
  • 165
  • 2
  • 7
  • 1
    I ran into this as well using a different version of Jenkins than the first system I tested it on. For v2.81 the top answer worked, but for LTS v2.83.x and any newer versions it gave the error you mentioned while your code still worked. – dragon788 Jan 24 '18 at 21:17
  • 2
    One thing I just noticed is you are sorting based on the `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. – dragon788 Oct 19 '18 at 16:35
8

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

http://<jenkinsurl>/systemInfo
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Andy G
  • 358
  • 4
  • 13
  • `/systeminfo` doesn't work (HTTP 404) on Jenkins 1.594 – G. Lombard Dec 22 '14 at 00:35
  • 7
    Try `http://localhost:8080/systemInfo` --some servers are case-sensitive. Note also that it requires the currently logged in user to have Overall/Administer permission. – MarkHu Jan 08 '16 at 18:22
4

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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
James Lawruk
  • 26,651
  • 19
  • 117
  • 128
  • 1
    The "installed plugins" page doesn't necessarily reflect the real plugin status. E.g. you might re-enable a plugin, and see the plugin checked, while the plugin is still disabled until Jenkins-Restart. Therefore, the only 100% solutions are http:///systeminfo and the API query answers, imho. – t0r0X Jul 13 '16 at 13:40
4

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/ /:/'
vishnu
  • 2,680
  • 1
  • 16
  • 6
  • as above, but without the versions, and sorted. `curl -sSL "http://127.0.0.1:8080/pluginManager/api/xml?depth=1&xpath=/*/*/shortName|/*/*/version&wrapper=plugins" | perl -pe 's/.*?([\w-]+).*?([^)+/\1 \n/g' | sort` – ffghfgh Jun 21 '17 at 15:57
3

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
Kevin Brotcke
  • 3,015
  • 22
  • 32
  • `grep Plugin-Version */META-INF/MANIFEST.MF | sed -e 's!/META-INF/MANIFEST.MF:Plugin-Version: !:!g' > ../plugins2.txt` – james dupont Apr 02 '20 at 13:38
2

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)
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Tidhar Klein Orbach
  • 2,471
  • 1
  • 25
  • 41
2

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
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
hhony
  • 341
  • 2
  • 5
1

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

user128364
  • 3,131
  • 2
  • 17
  • 12
1

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

1
# 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}")
    }
Brian
  • 21
  • 5
0

There is a table listing all the plugins installed and whether or not they are enabled at http://jenkins/systemInfo

tsuna
  • 1,816
  • 14
  • 21
0

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`
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Huluvu424242
  • 706
  • 8
  • 24
0

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
##############
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123