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

前端 未结 21 2195
误落风尘
误落风尘 2020-11-30 17:14

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 d

相关标签:
21条回答
  • 2020-11-30 17:43

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

    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)

    0 讨论(0)
  • 2020-11-30 17:44

    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/ /:/'
    
    0 讨论(0)
  • 2020-11-30 17:45

    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.

    0 讨论(0)
提交回复
热议问题