How to get a list of installed Jenkins plugins wit

2020-01-27 09:41发布

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 document or example?

21条回答
手持菜刀,她持情操
2楼-- · 2020-01-27 09:59

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
查看更多
够拽才男人
3楼-- · 2020-01-27 09:59

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)
查看更多
叼着烟拽天下
4楼-- · 2020-01-27 10:02

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

查看更多
疯言疯语
5楼-- · 2020-01-27 10:03

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

  • Jenkins > Manage Jenkins

    enter image description here

  • System Information

    enter image description here

  • Plugins

    enter image description here

查看更多
姐就是有狂的资本
6楼-- · 2020-01-27 10:06
# 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}")
    }
查看更多
Explosion°爆炸
7楼-- · 2020-01-27 10:07

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
查看更多
登录 后发表回答