Hello Jenkins Community!
Is there a way to reliably get the build number from a remotely triggered build?
Here's the process I use to remotely trigger a build
1) POST a http request to trigger a build
POST https://{hostname}/job/{job_name}/build
2) From the response's Location header, get the queue number of the build
Location: https://{hostname}/queue/item/673730/
3) Repeatedly send GET request to the queue
GET https://{hostname}/queue/item/673730/api/json?pretty=true
4) Get the build number
Response body:
{
...
"id": 67370,
"executable": {
"number": 18073,
"url": "https://{hostname}/job/{job_name}/18073/"
}
}
5) Use the build number to get the current status, console output, etc.
GET https://{hostname}/job/{job_name}/18073/consoleLogFull/api/json?pretty=true
Question is, is there a way for me to go from 1) to 3)? Or, another way to remotely build a Jenkins Job to 4) directly?
I'm seeing inefficiencies in having to continuously send a GET request at 2). Also, if the queue number becomes invalid (which happens a short while after build runs), then there's no way to get the build number.
I CANNOT use the 'latest build' option, since multiple job trigger may occur at once.
At least from the UI it seems that a job is given a build number as soon as it is triggered(through the UI)
Many suggestions appreciated, thx.