18

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)?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
citizenmatt
  • 18,085
  • 5
  • 55
  • 60

5 Answers5

36

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.

Phillip Ngan
  • 15,482
  • 8
  • 63
  • 79
  • 3
    Thanks for taking the time to answer this. This came up as the first result in Google for me and answered my query. You rock. – Ryan Bigg Mar 05 '13 at 02:09
  • 2
    Above will return only the builds that use `defaultBranch` (TeamCity 9.x). This locator will return all running builds: `locator=running:true,branch:default:any` – C0D3LIC1OU5 Mar 03 '16 at 19:17
4

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!

brandogs
  • 829
  • 7
  • 14
  • 1
    Hmm. I've tried to use running:true, but it just brings back the same list as when I don't include it. Digging in a bit more, it looks like the REST API only deals with essentially static or historic data, and not with the current status, such as currently running builds - can't seem to get that at all. Perhaps it's supported on a later version of TC (I'm on 5.1.5) – citizenmatt Jan 21 '11 at 18:11
  • In fact, it might be best to mix the REST API and the /win32/userStatus.html - it uses /ajax.html?getRunningBuilds=1 and /eventTracker.html. Oh well, had hoped for a nice, easy interface... – citizenmatt Jan 21 '11 at 18:57
  • That's very interesting about the running build dimension, Matt. I've never had a need to use running:true before; I just kept a little mental note about it when doing other things with the REST API. After playing with it a bit, I realized it doesn't seem to filter out the appropriate builds for me either. When you were looking into REST referencing historic data, did you stumble across the intended use of running:true? Sadly, I think you are right about needing a mix with the REST API. – brandogs Jan 21 '11 at 21:39
  • I was successful in calling the REST API to return the running builds. See the url I posted as an answer to the question. – Phillip Ngan Jul 14 '11 at 09:18
2

I realise your question is more than five years old, but you wanted

to find out which builds are currently running, and how far through they are (elapsed time vs estimated time)

The method as suggested in the accepted answer only gives the percentageComplete attribute, which is not as useful without having to make another call to the API.


It can be achieved by supplying the fields request parameter to the url, e.g.:

serverUrl/httpAuth/app/rest/builds/?locator=running:true&fields=count,build({buildFields})

where {buildFields} are properties of the builds object. For this, I am using:

id,buildTypeId,number,status,branchName,startDate,queuedDate,href,running-info

The full url is then

serverUrl/httpAuth/app/rest/builds/?locator=running:true&fields=count,build(id,buildTypeId,number,status,branchName,startDate,queuedDate,href,running-info)

which returns something like

<builds count="1">
    <build id="128990" buildTypeId="{build type ID}" number="256" status="SUCCESS" branchName="{branch name}" href="/httpAuth/app/rest/builds/id:128990">
        <running-info percentageComplete="6" elapsedSeconds="52" estimatedTotalSeconds="924" currentStageText="{status}" outdated="false" probablyHanging="false"/>
        <queuedDate>20160421T102558+0100</queuedDate>
        <startDate>20160421T105709+0100</startDate>
    </build>
</builds>

which will give you the percentage complete and elapsed/estimated total times in the running-info element.

Note: I am using TeamCity 9; the fields request parameter appears to be present in the documentation for TeamCity 5.x-7.x but the output may not be quite the same.

Community
  • 1
  • 1
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
0

You have a variant use not api -

[http://teamcity/ajax.html?getRunningBuilds=1]

So it's not good variant, but for me it's very good!

arturgspb
  • 1,004
  • 1
  • 12
  • 19
0

I did a little digging and a post on JetBrain's site stating that support for the running:true was actually added for TC6. TeamCity 5.X REST documentation just links to a different page which doesn't specify what was supported in TC5 and what is new to TC6.

EDIT: Hey Matt, I posted a question inquiring about REST documentation specific to TC 5.X. I know it would be very handy for me to know what exactly what I can do with REST for the version of TeamCity I am using and thought it may interest you as well!

Community
  • 1
  • 1
brandogs
  • 829
  • 7
  • 14