rest api to trigger a concourse pipeline/job
Asked Answered
R

1

7

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
Reefer answered 10/6, 2017 at 12:56 Comment(0)
S
2

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
Sloatman answered 15/6, 2017 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.