简体   繁体   中英

How to use Python-Jenkins to get multiple build status at any time?

I am very new to Python-Jenkins. I went through the API page but I don't find the answer.

I created a job in Jenkins, say MyJob. I want to use python to

  1. Add multiple builds for MyJob, which means execute server.build_job('MyJob', params) multiple times.
  2. Get one of created build status(finished or still waiting) at any time, which means I want get_build_info('MyJob', build_id)['result'] at any time.

More precisely, I am implementing a web server, there are requests that ask to create new builds(point 1) or query for status of created builds(point 2).

In API, build_id = server.get_job_info('MyJob')['nextBuildNumber'] can provide me the next build number, but I am unable to get this build's info using server.get_build_info('MyJob', build_id) at any time because if one build is in waiting queue, then we cannot use get_build_info to get its status, it will throw exception.

I don't understand, it's impossible for me to know when one build task would be put into execution, so when I am doing the query, one build can be any of (waiting in queue | executing | finished), then how could I get those builds' status? Actually I totally don't understand why get_build_info() doesn't support the situation when build task is in waiting queue.

You would need to get a queued build using get_queue_item

I would guess that the API doesn't see a build as a build until it has started running.

You could attempt to get the build info and if it throws an error (because it is in the queue) then pull it from the queue instead?

This doesn't seem the best documented module sadly, so what each call returns is a bit of a mystery without some trial and error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM