Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to retrieve id of Jenkins build I triggered via its API?

Tags:

jenkins

api

Let's say I trigger build by sending GET request to /job/awesomesauce/build. Is it possible to retrieve id of triggered build?

I'm aware I can try to access /job/awesomesauce/lastBuild/api/json, but that would give me erroneous information in case there are multiple builds running at once. Additionally, there seem to be slight delay (few seconds) before it gives me information about currently running build.

like image 810
Ondrej Slinták Avatar asked Mar 10 '12 19:03

Ondrej Slinták


2 Answers

I had to do this sort of thing, and here is a workaround I used: I had a dummy parameter that I passed to the build (in my case it was BUILD_ID of another build; in your case it may be a timestamp), I then queried and parsed both the build queue api ([server]/queue/api/...) and the regular api (in case the build has finished) for the build containing the appropriate parameter value.

like image 104
malenkiy_scot Avatar answered Sep 22 '22 20:09

malenkiy_scot


In the http response header "location", you can get the queue item id. Then you can poll /queue/item//api/json to get its executable number, which is the build id.

like image 25
jian Avatar answered Sep 25 '22 20:09

jian