gpt4 book ai didi

python - JenkinsAPI Python - 尝试获取构建信息

转载 作者:行者123 更新时间:2023-11-28 21:56:16 26 4
gpt4 key购买 nike

这是我使用 JenkinsAPI for Python 所做的

# Python scipt to get build information

# Import jenkins API and check Jenkins Version

import jenkinsapi
from jenkinsapi.jenkins import Jenkins
from jenkinsapi.build import Build

J = Jenkins('http://test.com')
job = J['MY_JOB_NAME']

print "Jenkins version:", J.version, "\n"

print jenkinsapi.api.get_latest_test_results('http://test.com','MY_JOB_NAME'), "\n"


B= Build('http://test.com',22,job)
print B.get_resultset()

我一直收到这个我无法理解的错误:

Traceback (most recent call last):
File "myscript.py", line 19, in <module>
print B
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 49, in __str__
return self._data['fullDisplayName']
KeyError: 'fullDisplayName'
svikani@myunix:~$ python myscript.py
Traceback (most recent call last):
File "myscript.py", line 19, in <module>
print B.get_resultset()
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 331, in get_resultset
result_url = self.get_result_url()
File "/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.2.18-py2.7.egg/jenkinsapi/build.py", line 325, in get_result_url
return url_tpl % (self._data["url"], config.JENKINS_API)
KeyError: 'url'

最佳答案

Build 实例中似乎有未初始化的变量。

您正在自己构建一个 Build 实例,但您可能应该通过 Jenkins 实例的 API 来获得您感兴趣的工作和构建.

import jenkinsapi
j = jenkinsapi.jenkins.Jenkins('http://jenkins:8080/')
job = j.get_job(JOB_NAME) # or j[JOB_NAME]
build = job.get_build(BUILD_ID)
print build.get_resultset()

关于python - JenkinsAPI Python - 尝试获取构建信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21715888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com