Search code examples
pythonjenkinsjenkins-pluginsjenkins-cli

Comparing the Jenkins plugins installed across instances


I have 6 Jenkins hosts and one production Jenkins hosts where we are using close to 100 plugins. We want to make sure that all the instances have same plugins and their respective versions.

We tried below curl command to retrieve list of plugins used by particular host. We are trying to develop the utility to compare the plugin versions across all the hosts and give us report if any plugin is missing on production host.

curl 'https://<Jenkins url>/pluginManager/api/xml?depth=1&x‌​path=/*/*/shortName|‌​/*/*/version&wrapper‌​=plugins' | perl -pe 's/.*?<shortName>([\w-]+).*?<version>([^<]+)()(<\/\w+>)+/\1 \2\n/g'

Solution

  • This is not a complete solution but you can definitely leverage Python libraries in order to compare the version incompatibilities OR missing plugins.

        import xml.etree.ElementTree as ET
    import requests
    import sys
    from itertools import zip_longest
    import itertools
    from collections import OrderedDict
    import collections
    import csv
    
    url = sys.argv[1].strip()
    filename = sys.argv[2].strip()
    
    response = requests.get(url+'/pluginManager/api/xml?depth=1',stream=True)
    response.raw.decode_content = True
    tree = ET.parse(response.raw)
    root = tree.getroot()
    data = {}
    for plugin in root.findall('plugin'):
        longName = plugin.find('longName').text
        shortName = plugin.find('shortName').text
        version = plugin.find('version').text
        data[longName] = version
        with open(filename, 'w') as f:
            [f.write('{0},{1}\n'.format(key, value)) for key, value in data.items()]
    

    Will give you the list of plugins in csv format!

    Which later can be used to compare with another instance and all this can be achieved in a single python script.