Jenkins plugins dependencies

Find transitive dependencies of a set of Jenkins plugins using update centre metadata



#!/usr/bin/env python3
# Finds the transitive closure of dependencies for a set of jenkins plugins.
# The jenkins puppet module does not resolve transitive dependencies, so all
# the transitive dependencies need to be listed in the yaml of plugins to
# install.
# This script reads JSON from the update centre for the relevant version of
# Jenkins. For Jenkins 2.60, run the following before this script:
#   curl -sLO
# The output of this script can be copied and pasted into the yaml (but may
# need the indentation adjusted).

from json import load
from yaml import dump

desired = [

def collect(plugins, plugin, dependencies=[]):
    current = plugins.get(plugin)
    if current is None:
        print('Unknown ', plugin)
    declared = current.get('dependencies')
    deps = [d.get('name') for d in declared if not d.get('optional')]
    for p in deps:
        if p not in dependencies:
            collect(plugins, p, dependencies)

def latest_versions(available, required):
    return {plugin: available.get(plugin).get('version')
            for plugin in required}

def to_yaml(versions):
    yaml = {plugin: {"version": version}
            for plugin, version in versions.items()}
    return dump(yaml, default_flow_style=None)

def main():
    with open('update-center.actual.json', 'r') as json:
        updates = load(json)
    plugins = updates.get('plugins')
    collected = []
    for plugin in desired:
        collect(plugins, plugin, collected)
    latest = latest_versions(plugins, collected)

if __name__ == "__main__":

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise © 2020