gpt4 book ai didi

jenkins - 如何让 jenkins API 返回更多构建?

转载 作者:行者123 更新时间:2023-12-04 08:36:14 25 4
gpt4 key购买 nike

我有一个脚本,可以从 jenkins 作业中提取工件并将其安装在我们的硬件测试系统上。现在,今天我需要降级到一个相当旧的版本。不幸的是,jenkins API 只返回最后几个构建。

我使用 jenkinsapi python API。它失败如下:

/usr/local/lib/python2.7/dist-packages/jenkinsapi-0.1.6-py2.7.egg/jenkinsapi/job.pyc in get_build(self, buildnumber)
177 def get_build( self, buildnumber ):
178 assert type(buildnumber) == int
--> 179 url = self.get_build_dict()[ buildnumber ]
180 return Build( url, buildnumber, job=self )
181

python API 访问 url http://jenkins/job/job-name/api/python/ .如果我自己这样做,那么我会得到以下响应:
{"actions":[{},{},{},{},{},{},{}],
"description":"text",
"displayName":"job-name",
"displayNameOrNull":None,
"name":"job-name",
"url":"http://jenkins/job/job-name/",
"buildable":True,
"builds":[
{"number":437,"url":"http://jenkins/job/job-name/437/"},
{"number":436,"url":"http://jenkins/job/job-name/436/"},
{"number":435,"url":"http://jenkins/job/job-name/435/"},
{"number":434,"url":"http://jenkins/job/job-name/434/"},
{"number":433,"url":"http://jenkins/job/job-name/433/"},
{"number":432,"url":"http://jenkins/job/job-name/432/"},
{"number":431,"url":"http://jenkins/job/job-name/431/"},
{"number":430,"url":"http://jenkins/job/job-name/430/"},
{"number":429,"url":"http://jenkins/job/job-name/429/"},
{"number":428,"url":"http://jenkins/job/job-name/428/"},
{"number":427,"url":"http://jenkins/job/job-name/427/"},
{"number":426,"url":"http://jenkins/job/job-name/426/"},
{"number":425,"url":"http://jenkins/job/job-name/425/"},
{"number":424,"url":"http://jenkins/job/job-name/424/"},
{"number":423,"url":"http://jenkins/job/job-name/423/"}],
"color":"yellow_anime",
"firstBuild": {"number":311,"url":"http://jenkins/job/job-name/311/"},
"healthReport":[
{"description":"Test Result: 0 tests failing out of a total of 3 tests.","iconUrl":"health-80plus.png","score":100},
{"description":"Build stability: No recent builds failed.","iconUrl":"health-80plus.png","score":100}],
"inQueue":False,
"keepDependencies":False,
"lastBuild":{"number":438,"url":"http://jenkins/job/job-name/438/"},
"lastCompletedBuild":{"number":437,"url":"http://jenkins/job/job-name/437/"},
"lastFailedBuild":{"number":386,"url":"http://jenkins/job/job-name/386/"},
"lastStableBuild":{"number":424,"url":"http://jenkins/job/job-name/424/"},
"lastSuccessfulBuild":{"number":437,"url":"http://jenkins/job/job-name/437/"},
"lastUnstableBuild":{"number":437,"url":"http://jenkins/job/job-name/437/"},
"lastUnsuccessfulBuild":{"number":437,"url":"http://jenkins/job/job-name/437/"},
"nextBuildNumber":439,
"property":[],
"queueItem":None,
"concurrentBuild":False,
"downstreamProjects":[],
"scm":{},
"upstreamProjects":[]}

现在,我想获得 315 号工作。我该怎么做?

最佳答案

我最终使用了以下解决方法:

try:
build=job.get_build(build_no)
except KeyError:
build=jenkinsapi.build.Build('%s%d/' % (job.baseurl, build_no), build_no, job=job)

它不漂亮,但它有效。

关于jenkins - 如何让 jenkins API 返回更多构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14316371/

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