eelou
asked on
How to use Rest APi to get Teamcity information
I am relatively new to Teamcity. I have created a project and configurations, run builds, etc. For a release, I need to create a report to send out, (for one project), I want to list all the configurations, the last build #, and the url for each configuration, to a report. What is the best way of doing this (they use Ant and Python here). Can someone give me (or point me to), an example of this (using the Rest API?). How to get the info, and then how to export this to a report\txt file. Basically, I am looking for the script example to do this. Please do not just point me to the teamcity rest documentation, I don't understand how to apply it in a script file. Do I need addition tools like curl, etc.?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The links above were helpful. The problem that I ran into was the user\password. This is what we came up with...
#!/usr/bin/python
# coding=utf8
import urllib.request
import base64
import xml.etree.ElementTree as ET
base64auth = base64.b64encode("{0}:{1}" .format("u sername", "password").encode("ascii" )).decode( "ascii").r eplace("\n ","")
#put real ip address below
url = "http://111.11.11.111/httpAuth/app/rest/projects/project111/buildTypes"
request = urllib.request.Request(url )
request.add_header("Author ization", "Basic {0}".format(base64auth))
response = urllib.request.urlopen(req uest)
Configurations = ET.fromstring(response.rea d().decode ('utf-8'))
for config in Configurations.findall('bu ildType'):
print ('{0},{1}'.format(config.a ttrib['nam e']," " + config.attrib['id']))
#!/usr/bin/python
# coding=utf8
import urllib.request
import base64
import xml.etree.ElementTree as ET
base64auth = base64.b64encode("{0}:{1}"
#put real ip address below
url = "http://111.11.11.111/httpAuth/app/rest/projects/project111/buildTypes"
request = urllib.request.Request(url
request.add_header("Author
response = urllib.request.urlopen(req
Configurations = ET.fromstring(response.rea
for config in Configurations.findall('bu
print ('{0},{1}'.format(config.a
The best library to do HTTP requests in Python is http://docs.python-requests.org/en/latest/