如何使用名称和版本对获取已安装的 Jenkins 插件列表 [英] How to get a list of installed Jenkins plugins with name and version pair

查看:34
本文介绍了如何使用名称和版本对获取已安装的 Jenkins 插件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取已安装的 Jenkins 插件列表?

我搜索了 Jenkins 远程访问 API 文档,但没有找到.我应该使用 Jenkins 的 CLI 吗?有文档或者例子吗?

解决方案

您可以使用

此解决方案类似于上述答案之一,因为它使用了 Groovy,但这里我们使用的是脚本控制台代替.脚本控制台在使用 Jenkins 时非常有用.

更新

如果您更喜欢排序列表,可以将其称为 sort 方法:

def pluginList = new ArrayList(Jenkins.instance.pluginManager.plugins)pluginList.sort { it.getShortName() }.each{插件 ->println ("${plugin.getDisplayName()} (${plugin.getShortName()}): ${plugin.getVersion()}")}

根据您的喜好调整关闭(例如,这里按 shortName 排序,在示例中按 DisplayName 排序)

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?

解决方案

You can retrieve the information using the Jenkins Script Console which is accessible by visiting http://<jenkins-url>/script. (Given that you are logged in and have the required permissions).

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)

这篇关于如何使用名称和版本对获取已安装的 Jenkins 插件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆