【发布时间】:2017-06-16 02:12:43
【问题描述】:
我需要在一组 Jenkins 服务器上测试我的自定义 Jenkins 插件 my-plugin.hpi。
我怎样才能最好地使用 Python 脚本?
【问题讨论】:
标签: python jenkins-plugins jenkins-api
我需要在一组 Jenkins 服务器上测试我的自定义 Jenkins 插件 my-plugin.hpi。
我怎样才能最好地使用 Python 脚本?
【问题讨论】:
标签: python jenkins-plugins jenkins-api
以下 Python 脚本使用 requests 模块和 Jenkins HTTP API 来执行相同的操作。
import requests
ciUrl = 'https://jenkins-server-url/my-ci-name'
files = {'file': open('my-plugin.hpi', 'rb')}
headers = {'Authorization':'Basic <base-64-encodeder-username-password>'}
### Uploading the HPI plugin file
r = requests.post(ciUrl + "/pluginManager/uploadPlugin", files=files, headers=headers, verify=False)
### Safe Restart the Jenkins to ensure plugin is installed.
r = requests.post(ciUrl + "/safeRestart", headers=headers, verify=False)
打印(r.text)
注意 verify=False 确保关闭 SSL 验证。如果您访问的是未知的 Jenkins 服务器,请设置 verify=True。
【讨论】: