Similar to how http://localhost/jenkins/job/job_name/25/api/json
would return a JSON
object with the details of build 26, is there a way to get a similar object when first initiating the job, i.e., before you know what the build number is?
I noticed the output from a curl
post request to the build url returns html
that includes a build number; however, I would prefer not to have to parse this in favor of having a JSON
object with the build number in it. Currently, I am using:
curl -v --data "param1=value¶m2=value" \
http://localhost/jenkins/job/job_name/buildWithParameters
which initiates the job fine and outputs a bunch of html
. Is there a way to start this job and receive a JSON
object with the build number?
The nextBuildNumber may not be the correct build number in all cases. If you have triggered two different builds of the same Job, we don't know which one got triggered first. There is a race condition here. Checking the build queue may not give the correct build number either.
If you query http://localhost/jenkins/job/job_name/api/json
you can fetch the nextBuildNumber
field anytime that will give you the next build number.
When you trigger a build, you can rest assured the build will get exactly this number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With