Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all unused jenkins plugins?

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)
like image 272
mastier Avatar asked Feb 16 '15 13:02

mastier


People also ask

How do I see unused plugins in Jenkins?

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.

How do I get a list of Jenkins plugins?

From the Jenkins home page: Click Manage Jenkins. Click Manage Plugins. Click on the Installed tab.

Where are Jenkins plugins stored?

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.


2 Answers

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

enter image description here

like image 98
Noam Manos Avatar answered Sep 29 '22 16:09

Noam Manos


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.

like image 23
gareth_bowles Avatar answered Sep 29 '22 16:09

gareth_bowles