Solved

How to use Rest APi to get Teamcity information

Posted on 2014-03-14
3
1,239 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 15

Accepted Solution

by:
Walter Ritzel earned 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now