Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use Rest APi to get Teamcity information

Posted on 2014-03-14
3
Medium Priority
?
1,633 Views
Last Modified: 2014-03-20
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.?
0
Comment
Question by:eelou
3 Comments
 
LVL 9

Expert Comment

by:techtonik
ID: 39929472
I am not familiar with Teamcity REST API, but in generic way REST API is just a bunch of URLs. You do GET or POST requests to these URLs to query info from them (URL itself specifies the item) and save result to variable.

The best library to do HTTP requests in Python is http://docs.python-requests.org/en/latest/
0
 
LVL 16

Accepted Solution

by:
Walter Ritzel earned 1500 total points
ID: 39935209
0
 

Author Comment

by:eelou
ID: 39942305
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("username", "password").encode("ascii")).decode("ascii").replace("\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("Authorization", "Basic {0}".format(base64auth))
response = urllib.request.urlopen(request)
Configurations = ET.fromstring(response.read().decode('utf-8'))

for config in Configurations.findall('buildType'):
      print ('{0},{1}'.format(config.attrib['name'],"  " + config.attrib['id']))
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
"Any files you do not have backed up in at least two [other] places are files you do not care about."
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question