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

前端 未结 21 2219
误落风尘
误落风尘 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:///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)

提交回复
热议问题