【问题标题】:Comparing the Jenkins plugins installed across instances比较跨实例安装的 Jenkins 插件
【发布时间】:2016-11-24 06:05:07
【问题描述】:

我有 6 台 Jenkins 主机和一台生产 Jenkins 主机,我们使用了近 100 个插件。我们要确保所有实例都具有相同的插件及其各自的版本。

我们尝试使用以下 curl 命令来检索特定主机使用的插件列表。我们正在尝试开发该实用程序来比较所有主机上的插件版本,并在生产主机上是否缺少任何插件时向我们报告。

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'

【问题讨论】:

    标签: python jenkins jenkins-plugins jenkins-cli


    【解决方案1】:

    这不是一个完整的解决方案,但您绝对可以利用 Python 库来比较版本不兼容性或缺少的插件。

        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()]
    

    会给你csv格式的插件列表!

    稍后可用于与另一个实例进行比较,所有这些都可以在单个 python 脚本中实现。

    【讨论】:

      【解决方案2】:

      我们在 shell 中这样做:

      java -jar jenkins-cli.jar -s <jenkins-url> list-plugins > <outputfile>
      

      然后我们使用不同主机的输出来确定差异。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-02
        • 1970-01-01
        • 2016-01-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多