Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rest api to trigger a concourse pipeline/job

I am able to use the below code to do a get request on the concourse api to fetch the pipeline build details. However post request to trigger the pipeline build does not work and no error is reported .

Here is the code

url = "http://192.168.100.4:8080/api/v1/teams/main/"
r = requests.get(url + 'auth/token')
json_data = json.loads(r.text)

cookie = {'ATC-Authorization': 'Bearer '+ json_data["value"]}
r = requests.post(url + 'pipelines/pipe-name/jobs/job-name/builds'
, cookies=cookie)

print r.text
print r.content

r = requests.get(url + 'pipelines/pipe-name/jobs/job-name/builds/17', cookies=cookie)
print r.text
like image 205
Vidya Avatar asked Jun 10 '17 12:06

Vidya


1 Answers

You may use Session :

[...] The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance [...]

url = "http://192.168.100.4:8080/api/v1/teams/main/"

req_sessions = requests.Session() #load session instance

r = req_sessions.get(url + 'auth/token')
json_data = json.loads(r.text)

cookie = {'ATC-Authorization': 'Bearer '+ json_data["value"]}
r = req_sessions.post(url + 'pipelines/pipe-name/jobs/job-name/builds', cookies=cookie)

print r.text
print r.content

r = req_sessions.get(url + 'pipelines/pipe-name/jobs/job-name/builds/17')
print r.text
like image 53
A STEFANI Avatar answered Oct 29 '22 17:10

A STEFANI