简体   繁体   English

从Jenkins REST API获取所有作业构建的构建详细信息

[英]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.

相关问题 如何以编程方式使用java获取jenkins中所有项目/工作的列表? - How to get the list of all projects/jobs in jenkins using java programmatically? Junit 5 with rest api(全部获取) - Junit 5 with rest api (get all) 如何让詹金斯建立其他所有项目 - How to get jenkins to build all other projects Azure REST API,用于从Azure门户获取所有用户的联系方式 - Azure REST API for fetching contact details of all users from azure portal Jenkins全天运行构建和测试 - Jenkins running builds and tests all day long 如何在Spring REST服务中获取所有传入的请求详细信息? - How to get all incoming request details in Spring REST service? 通过Groovy脚本从工件获取用于多个作业的最新内部版本号。 - Get the latest Build Number from artifactory for multiple jobs through Groovy script.Running from jenkins 在 springboot 中执行 getmapping 以获取单个 api 中所有实体的所有详细信息的列表 - to perform getmapping in springboot to get list of all details of all entities in a single api 列出所有由hudson制作的应用程序 - Application that lists all builds made from hudson 如何从REST API中读取错误详细信息 - How to read error details from REST API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM