How to get build ID effectively from remotely triggered builds.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get build ID effectively from remotely triggered builds.

Yoo JinSun
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.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a36d4800-69f6-4d8c-8ffa-66b6ce40318bo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to get build ID effectively from remotely triggered builds.

Vijay Gongle
Hello, 

I’m trying to build a jenkins job which is in jenkins server B from jenkins server A. 

How is it possible? 

Sent from my iPhone

On Jun 9, 2020, at 7:36 AM, Yoo JinSun <[hidden email]> wrote:


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.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/a36d4800-69f6-4d8c-8ffa-66b6ce40318bo%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/DB01A473-D0F3-4399-8FD9-A8DA25379911%40gmail.com.