【发布时间】:2011-01-20 18:25:39
【问题描述】:
有谁知道如何使用 TeamCity REST API 找出当前正在运行的构建以及它们的运行时间(经过的时间与估计的时间)?
Ta 马特
【问题讨论】:
-
我认为这些信息无法通过 REST API 获得。但如果可以的话,我会很高兴;)
有谁知道如何使用 TeamCity REST API 找出当前正在运行的构建以及它们的运行时间(经过的时间与估计的时间)?
Ta 马特
【问题讨论】:
URL 返回您要求的内容,包括完成百分比。 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#5291132。 REST API documentation 上的相关行显示为“http://teamcity:8111/httpAuth/app/rest/builds/?locator= - 通过“构建定位器”获取构建。”在“使用”部分。
这适用于 TeamCity 6.5 版;我没有在早期版本上尝试过,但我怀疑它会在版本 5 上运行。
【讨论】:
defaultBranch (TeamCity 9.x) 的构建。此定位器将返回所有正在运行的构建:locator=running:true,branch:default:any
您可以使用“running:true/false/any”作为构建定位器的构建维度之一。 (编辑:在 TeamCity 6.0 中添加)
http://confluence.jetbrains.net/display/TW/REST+API+Plugin
TeamCity REST API 文档将为您提供一些构建 URL 方法的示例。该页面上的 Build Locator 部分将列出您用于优化结果的不同选项(其中一个正在运行)。
但是,我不知道如何使用 REST API 获取有关正在运行的构建经过/估计的时间的信息。我不确定这是否可能。如果您确实找到了这样做的方法,我将非常有兴趣了解如何!
祝你好运!
【讨论】:
我知道你的问题已经超过五年了,但你想要
找出当前正在运行的构建,以及它们的运行时间(经过的时间与估计的时间)
accepted answer 中建议的方法只提供了percentageComplete 属性,如果不再次调用 API,它就没有那么有用了。
可以通过将fields request parameter 提供给 url 来实现,例如:
serverUrl/httpAuth/app/rest/builds/?locator=running:true&fields=count,build({buildFields})
其中{buildFields} 是builds 对象的属性。为此,我正在使用:
id,buildTypeId,number,status,branchName,startDate,queuedDate,href,running-info
那么完整的url就是
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,但输出可能不完全相同。
【讨论】:
我做了一点挖掘,a post on JetBrain's site 声明实际上是为 TC6 添加了对 running:true 的支持。 TeamCity 5.X REST documentation 只是链接到一个不同的页面,它没有指定 TC5 支持的内容以及 TC6 的新内容。
编辑:嘿,马特,我发布了一个关于 REST documentation specific to TC 5.X 的问题。我知道我知道我可以用 REST 对我正在使用的 TeamCity 版本做些什么对我来说非常方便,并且我认为它也可能会让你感兴趣!
【讨论】:
你有一个变体使用不是 api -
[http://teamcity/ajax.html?getRunningBuilds=1]
所以它不是很好的变种,但对我来说它非常好!
【讨论】: