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)
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.
From the Jenkins home page: Click Manage Jenkins. Click Manage Plugins. Click on the Installed tab.
When Jenkins runs, it stuffs all of its logs, cloned repos, plugin configurations and build artifacts into the Jenkins Home folder. Basically, every ounce of configuration that exists for your Jenkins installation is contained in the Jenkins Home directory.
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):
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With