How to list all unused jenkins plugins?
jenkins, jenkins-plugins, python
Solution
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 have no dependencies).
The plugin interface has a link on Jenkins sidebar. It lists all the plugins which have extension points in existing jobs (press on the expand button to see which jobs), and global plugins as well:
Update: Pipeline jobs are now supported (Thanks Ian W)
Problem
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) ```