I need to get the ID of a jenkins job that I start using the REST API (using python). Since Jenkins 1.529, it seems to be possible to trigger a build using the API abd to get in return an url pointing to the job in the queue.
Documentation of Jenkins:
Perform a build
To programmatically schedule a new build, post to this URL. If the build has parameters, post to this URL and provide the parameters as form data. Either way, the successful queueing will result in 201 status code with Location HTTP header pointing the URL of the item in the queue. By polling the api/xml sub-URL of the queue item, you can track the status of the queued task. Generally, the task will go through some state transitions, then eventually it becomes either cancelled (look for the "cancelled" boolean property), or gets executed (look for the "executable" property that typically points to the AbstractBuild object.)
But I do not succeed in getting an useful url.
I tried:
import requests
requestKwargs ={'headers': {'Content-Type': 'application/x-www-form-urlencoded'}, 'data': {'json': '{"parameter": []}'}, 'verify': True}
url=server+'job/test/build/'
req=requests.post(url, **requestKwargs)
print 'status',req.status_code
location=req.headers['location']
print 'location is:',location
The output of this code is:
status 201
location is: http://SERVER_PORT/job/test/build/
How can I use the information of "location" to track the status of the queue task?
Thanks.