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

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

    Jenkins 1.588 (2nd of November, 2014) & 1.647 (4th of February, 2016)

    • Jenkins > Manage Jenkins

    • System Information

    • Plugins

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

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

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

    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

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

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

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

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