Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity - how to get currently running builds via REST API?

Tags:

rest

teamcity

Does anyone know how to use the TeamCity REST API to find out which builds are currently running, and how far through they are (elapsed time vs estimated time)?

Ta Matt

like image 215
citizenmatt Avatar asked Jan 20 '11 18:01

citizenmatt


People also ask

How do I use my TeamCity API?

TeamCity REST API It allows accessing resources via URL paths. You can start working with the REST API by opening the http://<TeamCity Server host>:<port>/app/rest/server URL in your browser: this page gives several pointers to explore the API. To learn more, proceed to the dedicated TeamCity REST API Help.

What is build locator in TeamCity?

BuildLocator Last modified: 26 July 2022. Represents a locator string for filtering Build entities. Examples: id:1 — find build with ID 1 .

How do I cancel a build on TeamCity?

To stop a running build:Click Stop build link, which becomes available, while the build is in progress. In the Stop build dialog, enter your comment, and click OK.


2 Answers

You can use "running:true/false/any" as one of the build dimensions for the build locator. (EDIT: added in TeamCity 6.0)

http://confluence.jetbrains.net/display/TW/REST+API+Plugin

The TeamCity REST API documentation will give you some examples of some of the ways you can construct the URL. The Build Locator section on that page will list the different options you have for refining your results (one of which is running).

However, I don't know of a way to get information about the running builds elapsed/estimated time using the REST API. I'm not sure if this would be possible. If you did find a way to do this, I would be be very interested to read how!

Good luck!

like image 25
brandogs Avatar answered Oct 06 '22 23:10

brandogs


The URL returns what you are asking for, including percentage complete. http://teamcityserver/httpAuth/app/rest/builds?locator=running:true

<builds count="1">
    <build id="10" number="8" running="true" percentageComplete="24" status="SUCCESS" buildTypeId="bt3" startDate="20110714T210916+1200" href="/httpAuth/app/rest/builds/id:10" webUrl="http://phillipn02:29000/viewLog.html?buildId=10&buildTypeId=bt3"/>
</builds>

Source: http://devnet.jetbrains.net/message/5291132#5291132. The relevant line on the REST API documentation is the one that reads "http://teamcity:8111/httpAuth/app/rest/builds/?locator= - to get builds by "build locator"." in the "Usage" section.

This works with TeamCity version 6.5; I haven't tried it on earlier versions, but I suspect it will work back to version 5.

like image 57
Phillip Ngan Avatar answered Oct 07 '22 01:10

Phillip Ngan