我正在寻找一种方法来检查哪些Jenkins插件没有被使用。 到目前为止,我发现可以查找具有属性plugin的config.xml文件中的标签,然后将其与plugins目录中列出的标签进行比较。 但这并不能给我完整的列表。仍然有一些像role-strategy这样的插件不在那里。
我使用类似下面的Python代码:
#!/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)