python - 比较跨实例安装的 Jenkins 插件

标签 python jenkins jenkins-plugins jenkins-cli

我有 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 库来比较版本不兼容或缺少的插件。

    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 脚本中实现。

关于python - 比较跨实例安装的 Jenkins 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40779083/

相关文章:

python - 将灰度图像转换为蓝色和红色图像

git - 当在同一个提交上推送新标签时,jenkins 不会触发构建

jenkins-plugins - Jenkins - Git 客户端插件在通过 HTTP 代理连接时抛出 Http-503 错误

java - 如何在 maven 中设置 java.util.logging 日志级别(用于 Jenkins 插件 (JenkinsRule) 测试)

python - 如何使用 Python 读取包含扩展字体的 Excel 文件? (openpyxl 错误 : Max value is 14)

python - Python IDLE Shell 的令人困惑的问题

python - 从 Sklearn 管道中使用特征名称提取特征重要性

docker - 在 docker 容器中安装包

git - Jenkins 配置

docker - 如何根据分支名称在Jenkins中更改Agent标签