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

cgh8pdjw  于 5个月前  发布在  Python
关注(0)|答案(1)|浏览(70)

我想在Python中实现currentbuild.rawbuild.getcauses()。我该怎么做?该函数目前是groovy脚本的一部分,需要转换为Python。
我似乎找不到任何东西。下面的链接是最接近我能找到的:
Getting current build number in jenkins using python

iqih9akk

iqih9akk1#

您可以使用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/"
    }
  ]
},

相关问题