Refer - https://stackoverflow.com/a/51517348
I'll leave the original question as is and elaborate here on the various API calls to trigger parameterized builds. These are the calls options that I used.
Additional documentation: https://wiki.jenkins.io/display/JENKINS/Remote+access+API
The job contains 3 parameters named: product, suites, markers
Send the parameters as URL query parameters to /buildWithParameters: http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=ALL&suites=ALL&markers=ALL
Send the parameters as JSON data\payload to /build: http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build
The JSON data\payload is not sent as the call's json_body (which is what confused me), but rater in the data payload as:
json:'{
"parameter": [
{"name":"product", "value":"123"},
{"name":"suites", "value":"high"},
{"name":"markers", "value":"Hello"}
]
}'
And here are the CURL commands for each of the above calls:
curl -X POST -H "Jenkins-Crumb:2e11fc9...0ed4883a14a" http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/build --user "raameeil:228366f31...f655eb82058ad12d" --form json='{"parameter": [{"name":"product", "value":"123"}, {"name":"suites", "value":"high"}, {"name":"markers", "value":"Hello"}]}'
curl -X POST \ 'http://jenkins:8080/view/Orion_phase_2/job/test_remote_api_triggerring/buildWithParameters?product=234&suites=333&markers=555' \ -H 'authorization: Basic c2hsb21pb...ODRlNjU1ZWI4MjAyOGFkMTJk' \ -H 'cache-control: no-cache' \ -H 'jenkins-crumb: 0bed4c7...9031c735a' \ -H 'postman-token: 0fb2ef51-...-...-...-6430e9263c3b'
What to send to Python's requests In order to send the above calls in Python you will need to pass:
headers = jenkins-crumb
auth = tuple of your (user_name, user_auth_token)
data = dictionary type { 'json' : json string of {"parameter":[....]} }
Refer - https://stackoverflow.com/a/22289625
've worked around this issue by providing an 'ident' param to jobs that I wish to interact with programatically.
When submitting the job, I generate a uuid and submit this as the ident param to /job/<job_name>/buildWithParameters.
I then get /queue/api/json and iterate through the list of queued items, searching for an item with that uuid in it's params. That gets the queue id.
I then use this queue id to poll /queue/item/<queue_id>/api/json every N seconds, waiting for jenkins to provide a build number in the response (it will once the build has started). You can use this build number to construct the url you want, /job/<job_name>/<build_number>.
You actually need to add the ident as a param in your jenkins job. It's a pain, but it works reliably.