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

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

提交回复
热议问题