TeamCity - 如何通过REST API获取当前正在运行的构建?

时间:2011-01-20 18:25:39

标签: rest teamcity

有没有人知道如何使用TeamCity REST API来找出当前正在运行的构建版本,以及它们有多远(经过时间与估计时间)?

钽 马特

5 个答案:

答案 0 :(得分:31)

网址会返回您要求的内容,包括完成百分比。   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>

来源:http://devnet.jetbrains.net/message/5291132#5291132REST API documentation上的相关行是“http:// teamcity:8111 / httpAuth / app / rest / builds /?locator = - 通过”构建定位器“获取构建的行。”在“使用”部分。

这适用于TeamCity 6.5版;我没有在早期版本上尝试过,但我怀疑它会恢复到第5版。

答案 1 :(得分:4)

您可以使用“running:true / false / any”作为构建定位器的构建维度之一。 (编辑:在TeamCity 6.0中添加)

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

TeamCity REST API文档将为您提供一些构建URL的方法示例。该页面上的“构建定位器”部分将列出用于优化结果的不同选项(其中一个正在运行)。

但是,我不知道如何使用REST API获取有关正在运行的构建已过去/估计时间的信息。我不确定这是否可行。如果你确实找到了这样做的方法,我将非常有兴趣阅读如何!

祝你好运!

答案 2 :(得分:1)

我意识到你的问题已超过五年,但你想要

  

找出当前正在运行的构建版本,以及它们的持续时间(已用时间与估计时间)

accepted answer中建议的方法仅提供percentageComplete属性,如果不再调用API,则该属性无效。

可以通过向网址提供fields request parameter来实现,例如:

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

其中{buildFields}builds对象的属性。为此,我正在使用:

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

然后是完整的网址

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

返回类似

的内容
<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>

将为您提供running-info元素中完整和已过去/估计总时间的百分比。

注意:我正在使用TeamCity 9; TeamCity 5.x-7.x文档中的字段请求参数appears to be present,但输出可能不完全相同。

答案 3 :(得分:0)

我做了一点挖掘并且a post on JetBrain's site说明对TC6实际上添加了对running:true的支持。 TeamCity 5.X REST documentation只链接到另一个页面,该页面未指定TC5中支持的内容以及TC6的新内容。

编辑:嘿马特,我发了一个询问REST documentation specific to TC 5.X的问题。我知道,对于我正在使用的TeamCity版本,我可以使用REST做什么,这对我来说非常方便,并且认为它也可能对您感兴趣!

答案 4 :(得分:0)

您使用的变体不是api -

[HTTP://teamcity/ajax.html getRunningBuilds = 1]

所以这不是好变种,但对我来说这非常好!

相关问题