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
Vidya
  • 7,717
  • 12
  • 48
  • 75

1 Answers1

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
A. STEFANI
  • 6,707
  • 1
  • 23
  • 48