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

15,586

Solution 1

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.

Solution 2

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!

Solution 3

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.

Share:
15,586

Related videos on Youtube

citizenmatt
Author by

citizenmatt

Updated on May 17, 2022

Comments

  • citizenmatt
    citizenmatt almost 2 years

    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

  • citizenmatt
    citizenmatt about 13 years
    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
    citizenmatt about 13 years
    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...
  • brandogs
    brandogs about 13 years
    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.
  • INF.TA
    INF.TA over 12 years
    I was successful in calling the REST API to return the running builds. See the url I posted as an answer to the question.
  • owl
    owl about 11 years
    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.
  • C0D3LIC1OU5
    C0D3LIC1OU5 about 8 years
    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