如何列出所有未使用的jenkins插件? [英] How to list all unused jenkins plugins?

查看:338
本文介绍了如何列出所有未使用的jenkins插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找检查未使用哪些jenkins插件的方法. 到目前为止,我发现我可以在属性为 plugin config.xml 文件中查找标签,然后将其与 plugins 目录中列出的标签进行比较. 但这并没有给我完整的清单.还有一些还不存在,例如 role-strategy .

I am looking for method to check which jenkins plugins are not used. So far I found that I can look for tags in config.xml file with attribute plugin then compare them with the ones listed in plugins directory. But that does not give me complete list. Still some are not there like role-strategy.

我使用如下所示的python代码

I use python code like below

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import glob
from lxml import etree as ET
from collections import defaultdict

def find(name, path):
    return glob.glob(path+'/jobs/*/'+name)


def get_plugin_list(path):
    return [x[:-4].split('/')[-1] for x in glob.glob(path+'/plugins/*.jpi')]


if __name__ == "__main__":
    jobs_dict = defaultdict(list)
    plugins_all = set(get_plugin_list('/home/user/.jenkins')
    for config in find('config.xml', '/home/user/.jenkins'):
        with open(config) as f:
            tree = ET.XML(f.read())
            plugins = tree.xpath("/project//@plugin")
        job = config.split('/')[-2]
        for p in plugins:
            jobs_dict[p].append(job)
    with open('/home/user/.jenkins/config.xml') as f:
        tree = ET.XML(f.read())
        plugins_config = tree.xpath("/hudson//@plugin")
    plugins_used = set([x.split('@')[0] for x in jobs_dict.keys()+plugins_config])
    print "######## All plugins\n", '\n'.join(plugins_all)
    print "######## Used plugins\n", '\n'.join(plugins_used)
    print "######## Unused plugins\n", '\n'.join(plugins_all - plugins_used)

推荐答案

有一个专门针对此问题的Jenkins插件: 插件使用情况

There's a Jenkins plugin precisely for this matter: Plugin Usage

借助这个出色的插件,我在插件管理器中发现了许多要删除的冗余插件(您将能够删除没有依赖性的插件).

Thanks to this wonderful plugin I found many redundant plugins to remove in the Plugin Manager (you will be able to remove plugins that has no dependencies).

外观如下-插件界面在Jenkins侧边栏上有一个链接.它列出了任何现有作业使用的所有插件(按扩展按钮以查看作业名称):

Here's how it looks - the plugin interface has a link on Jenkins sidebar. It lists all the plugins which any of an existing job uses (pressing on the expand button to see jobs names):

这篇关于如何列出所有未使用的jenkins插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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