forked from cdancy/jenkins-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
RunningABuild
Martin d'Anjou edited this page Jun 6, 2018
·
2 revisions
Perhaps the most powerful use of the jenkins-rest is when the REST API calls are combined to submit a job, track its progress and report on the build status.
At a high level, the steps to submit a job and track it to its completion are:
- Call the
JobsApi
build
method. This returns anIntegerResponse
instance with the queue id number of the submitted job - Poll the
QueueApi
queueItem
method using the queue id number from theInteger Response
. Polling returns aQueueItem
instance which contains the state of the build in the queue. The state could be a:- build cancellation before the build even starts (abort the polling, the build will never run)
- build pending (continue to wait or time out)
- build executing with a build number (stop polling the queue)
- Poll the
JobsApi
buildInfo
method using theQueueItem
build number. This returns aBuildInfo
instance. When theresult
method no longer returns null, the build is done and theresult
method returns a string representing the build status (passed, failed, etc).
A complete example is available in RunningABuild.groovy.
With a live instance of Jenkins running, the example can be executed like so:
export JENKINS_REST_CREDENTIALS=user:password
export JENKINS_REST_ENDPOINT=http://localhost:8080/
groovy RunningABuild.groovy