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

标签 python python-2.7 jenkins jenkins-plugins

这是我使用 Python 的 JenkinsAPI 所做的事情

# 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/

相关文章:

jenkins - Jenkins 共享库中的全局变量

jenkins - 无法为Jenkins设置Kubernetes插件

python - 如何将一串数字转换回二进制十六进制(\x 值)类型?

python - fillna 与 None 串联

python - 在 Homebrew 上结束对 python 2 的支持后,在 Mac 上安装 python@2

python 运算符 'in' 与正则表达式

Jenkins 同一构建的多个工件

python - 如何使用 "with"调用 tempfile.mkstemp() ? - 或者为什么它不返回带有 __exit__() 的 fd?

python - 在处理上述异常的过程中,又发生了异常

javascript - 如何打开要在其中运行 javascript 的 Ghost 本地 html 文件?