如何使用Python获取Jenkins中当前构建的失败原因?

问题描述 投票:0回答:1

我想在Python中实现currentbuild.rawbuild.getcauses()。我怎样才能做到这一点? functn 目前是 groovy 脚本的一部分,需要转换为 Python。

我似乎没有找到任何东西。以下链接最接近我能找到的内容:

使用 python 获取 jenkins 中的当前版本号

python jenkins groovy jenkins-groovy
1个回答
0
投票

您可以使用 Jenkins 的 Python API:

http://my-jenkins/job/my-job/my-build-number/api/python

这将包括有关构建的信息,包括构建原因。从主 api 页面 http://my-jenkins/job/my-job/my-build-number/api:

Python API

为 Python 客户端访问与 Python 相同的数据。这可以解析为 Python 对象:

ast.literal_eval(urllib.urlopen("...").read())
以及由此产生的 对象树与 JSON 的对象树相同。

返回数据示例(摘录):

{
  "_class" : "hudson.model.CauseAction",
  "causes" : [
    {
      "_class" : "hudson.model.Cause$UpstreamCause",
      "shortDescription" : "Started by upstream project \"my_upstream_build\" build number 123",
      "upstreamBuild" : 123,
      "upstreamProject" : "my_upstream_build",
      "upstreamUrl" : "job/my_upstream_build/"
    }
  ]
},
© www.soinside.com 2019 - 2024. All rights reserved.