How to list all unused jenkins plugins?

核能气质少年 提交于 2019-12-09 14:44:01

问题


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.

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)

回答1:


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

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




回答2:


Some plugins only affect the Jenkins system configuration, rather than individual jobs; you should be able to find those by changing the find method in your code to include /home/user/.jenkins/config.xml.

Many plugins have their own configuration files in $JENKINS_HOME, e.g. $JENKINS_HOME/org.jenkinsci.plugins.p4.PerforceScm.xml. I haven't looked into this, but your might be able to find some extra plugin usage by searching the config.xml files for the plugin name (e.g. PerforceSCM) rather than the term "plugin".

Also, if you only want to search for jobs that are enabled, you can filter out jobs with "<disabled>true</disabled>" in their config.xml.




回答3:


If you need to check the list of installed but disabled plugins you can check Installed tab in plugin manager.

Unchecked are the ones that are disabled.



来源:https://stackoverflow.com/questions/28542644/how-to-list-all-unused-jenkins-plugins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!