[英]Get build details for all builds of all jobs from Jenkins REST API
I have a hosted Jenkins server and from there, I am trying to fetch the build details (like result, timestamp, duration etc.) for all the jobs using the Jenkins REST API and then save it in my database. 我有一个托管的Jenkins服务器,从那里,我试图使用Jenkins REST API获取所有作业的构建细节(如结果,时间戳,持续时间等),然后将其保存在我的数据库中。
Right now, I am calling the following API from my Java code, to fetch all the jobs (about 200 jobs): 现在,我从我的Java代码调用以下API来获取所有作业(大约200个作业):
https://<JENKINS_HOST>/api/json
Then I fetch the job details and all the builds for each job by using: 然后我使用以下方法获取每个作业的作业详细信息和所有构建:
https://<JENKINS_HOST>/job/MY_JOB/api/json
Then finally, for each of the builds (I have to fetch only last 50), I have to call this to fetch the build details: 最后,对于每个构建(我只需要获取最后50个),我必须调用它来获取构建细节:
https://<JENKINS_HOST>/job/MY_JOB/<BUILD_NUMBER>/api/json
So that makes it about a total of 50*200 + 201 = over 10000 API calls. 因此,它使得总共50 * 200 + 201 =超过10000个API调用。
I am guessing, These many API calls would make the Jenkins server perform slow? 我猜,这些API调用会让Jenkins服务器执行速度慢吗?
So, my question is is there a faster/more optimal way to do this, So that I do not have to make so many API calls? 所以,我的问题是有更快/更优化的方法来做到这一点,所以我不必进行这么多的API调用吗?
Something like where I can fetch all the build details using one url like this: (hypothetically) 像我这样可以使用这样的一个URL获取所有构建细节的地方:(假设)
https://<JENKINS_HOST>/job/MY_JOB/api/json?fetchAllbuildDetails=True
In case, anyone else is stuck with the same, I was able to get this done using the tree: 万一,其他任何人都坚持使用相同的,我能够使用树完成这个:
https://<JENKINS_HOST>/api/json?tree=jobs[name,url,builds[number,result,duration,url]]
Here, column names can be filtered to fetch only the data you need as the amount of data returned from this is huge. 在这里,可以过滤列名称以仅获取所需的数据,因为从此返回的数据量很大。
You can also limit the number of records to be fetched like this: 您还可以限制要提取的记录数,如下所示:
https://<JENKINS_HOST>/api/json?tree=jobs[name,url,builds[number,result,duration,url]{0,50}]
This will fetch only the last 50 builds for all the jobs, which is exactly what I needed. 这将只获取所有作业的最后50个构建,这正是我所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.