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

前端 未结 21 2194
误落风尘
误落风尘 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:28

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

    0 讨论(0)
  • 2020-11-30 17:29
    # 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}")
        }
    
    0 讨论(0)
  • 2020-11-30 17:31

    These days I use the same approach as the answer described by @Behe below instead 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
    
    0 讨论(0)
  • 2020-11-30 17:31

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

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

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

    http://<jenkinsurl>/systemInfo
    
    0 讨论(0)
提交回复
热议问题