TeamCity - how to get currently running builds via

2020-06-08 13:00发布

问题:

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

回答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.



回答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!



回答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.



回答4:

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!



回答5:

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!



标签: rest teamcity