使用TeamCity REST API跟踪构建进度 [英] Tracking build progress with TeamCity REST API

查看:235
本文介绍了使用TeamCity REST API跟踪构建进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TeamCity(7.0)REST API来允许开发人员触发自定义构建。我像这样将队列添加到队列:

I use the TeamCity (7.0) REST API to allow developers to trigger custom builds. I add the build to the queue like this:

http://teamcity/httpAuth/action.html?add2Queue = [buildTypeId]& name = [propName]& ; value = [propValue]

http://teamcity/httpAuth/action.html?add2Queue=[buildTypeId]&name=[propName]&value=[propValue]

我的问题是我如何最好地跟踪刚触发的构建进度。 REST调用不返回任何关于分配给构建的构建ID的信息,因此即使我轮询构建列表(运行/完成),我也不知道其中一个是否是我触发的构建。在队列中可能会有相同的buildTypeId的几个构建,所以我需要一个方法来分离我之后的一个。

My question is how I best can track the progress of the build just triggered. The REST call does not return any info about build ID assigned to the build, so even if I poll the list of builds (running/finished) I will not know if one of them is the one I triggered. There could potentially be several builds for the same buildTypeId in the queue, so I need a way to separate out the one I am after.

我在某处读到一个建议,你可以为您放入队列的每个构建添加具有唯一值的构建属性,然后再轮询构建列表并查找具有该确切属性值的构建属性。我还没有找到一个方法列出的属性的构建,所以我仍然卡住。此REST调用不提供有关属性的信息:

I read somewhere a suggestion that you could add a build property with a unique value to each build you put in the queue, and then later poll the build list and look for one with that exact property value. I have however not found a way of listing the properties for the builds, so I am still stuck. This REST call does not provide information about properties:

http:// teamcity / httpAuth / app / rest / builds /?locator = buildType:[buildTypeId]

http://teamcity/httpAuth/app/rest/builds/?locator=buildType:[buildTypeId]

有关如何解决这个问题的任何建议?我理想地想知道如果构建是在队列中,如果它正在运行,当它完成我想获得状态。

Any suggestions on how to solve this? I would ideally like to know if the build is in the queue, if it is running, and when it's done I would like to get the status. The most important is however to know if it is done and what the status has.

推荐答案

经过进一步的调查后,我想出了一个解决方案,这似乎工作正常:

After some further investigation I came up with a solution for this which seems to work fine:

我发现,即使你没有得到任何关于自定义构建属性的信息使用/ builds /?定位器= buildType:x调用,可以为该列表中的每个构建提取构建标识,然后执行另一个REST调用以获取有关一个特定构建的更多详细信息。其余调用如下所示:

I found out that even though you did not get any information about the custom build properties using the "/builds/?locator=buildType:x" call, you could extract the build ID for each one of the builds in that list and then do another REST call to get more details about one specific build. The rest call looks like this:

http://teamcity/httpAuth/app/rest/builds/id:{0}

此调用的响应将为您提供一个构建对象,其中包含构建属性的列表,

The response from this call will give you a "build object" which contains a list of build properties, among other things.

我的解决方案跟踪构建进度如下:

My solution for tracking the build progress was then like this:

添加到TeamCity队列,我首先添加一个属性到名为BuildIdentifier的URL。该值只是一个GUID。我将此标识符传回客户端应用程序,然后客户端开始轮询服务器,请求具有此特定标识符的构建状态。然后服务器通过一些步骤来识别构建的当前阶段:

When a build is added to the TeamCity queue, I first add a property to the URL called "BuildIdentifier". The value is just a GUID. I pass this identifier back to the client application, and then the client starts polling the server, asking for the status of the build with this specific identifier. The server then goes through some steps to identify the current stage of the build:

1:检查构建是否正在运行。我通过调用/ builds?locator = running:true获取运行构建的列表,遍历构建并使用构建ID来查询REST API的详细信息。然后,我将详细介绍每个运行的构建,查找具有匹配的BuildIdentifier属性的构建,以获取从客户端收到的属性。如果在正在运行的构建中存在匹配,我会向跟踪进度的客户机发送一个响应,其中包含构建以百分之x(构建对象的PercentageComplete属性)运行的消息。如果没有找到匹配,我将转到第2步。

1: Check if the build is running. I get the list of running builds with the call "/builds?locator=running:true", iterate through the builds and use the build ID to query the REST API for details. I then go through the details for each running build looking for a build with a matching "BuildIdentifier" property to the one I received from the client. If there is a match in one of the running builds I send a response with a message that the build is running at x percent (PercentageComplete property of the build object) to the client who is tracking the progress. If a match is not found I move on to step 2.

2:检查是否完成:首先使用/ builds /?locator = buildType:x调用。然后做与步骤1相同的事情,并从列表中提取X最新的版本(我选择5)。为了限制REST调用的数量,我设置一个假设,如果完成,构建将在最近的5个构建中。然后我在BuildIdentifier上寻找一个匹配,如果我得到一个,我返回构建的状态(FAILED,SUCCESS等)。

2: Check if it is finished: First get the latest build list using the "/builds/?locator=buildType:x" call. Then do the same thing as in step 1, and extract the X latest builds from the list (I chose 5). In order to limit the number of REST calls I set an assumption that the build would be in the latest 5 builds if it was finished. I then look for a match on the BuildIdentifier, and if I get one I return the status of the build (FAILED, SUCCESS, etc.).

3:在步骤1或2中没有与BuildIdentifier匹配我可以假设该构建在队列中,所以我返回作为当前状态。

3: If there was no match for the BuildIdentifier in step 1 or 2 I can assume that the build is in the queue, so I return that as the current status.

在客户端我轮询服务器的状态每x秒,只要状态是说生成是在队列中,或正在运行。

On the client side I poll the server for the status every x seconds as long as the status is saying that the build is either in the queue, or running.

希望这个解决方案可以有帮助,如果有别人有相同的问题在那里!如果您使用TeamCity REST API,我认为跟踪触发的构建的进度是一个非常常见的任务。

Hope this solution could be helpful if there are someone else with the same problem out there! I would think that tracking the progress of a triggered build is a pretty common task if you use the TeamCity REST API.

这篇关于使用TeamCity REST API跟踪构建进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆