Reputation: 173
I am trying to launch a Jenkins parametrized job from a python script. Due to environment requirements, I can't install python-jenkins. I am using raw requests module.
This job I am trying to launch has three parameters:
I've searched and search, without any success.
I managed to launch the job with two string parameters by launching:
import requests
url = "http://myjenkins/job/MyJobName/buildWithParameters"
target = "http://10.44.542.62:20000"
payload = "{payload: content}"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
msg = {
'token': 'token',
'payload': [ payload ],
'target': [ target ],
}
r = requests.post(url, headers=headers, data=msg)
However I am unable to send a file and those arguments in single request.
I've tried requests.post
file argument and failed.
Upvotes: 1
Views: 1409
Reputation: 173
It turns out it is impossible to send both data and file in a single request via HTTP.
Upvotes: 1
Reputation: 22089
Here is an example:
curl -vvv -X POST http://127.0.0.1:8080/jenkins/job/jobname/build
--form file0='@/tmp/yourfile'
--form json='{"parameter": [{"name":"file", "file":"file0"}]}'
--form json='{"parameter": [{"name":"payload", "value":"123"}]
--form json='{"parameter": [{"name":"target", "value":"456"}]}'
Upvotes: 0
Reputation: 41
import jenkinsapi from jenkinsHandler import JenkinsHandler in your python script
Pass parameters to buildJob() , (like < your JenkinsHandler object name>.buildJob()) JenkinsHandler module has functions like init() , buildJob(), isRunning() which helps in triggering the build
Upvotes: 0