如何通过TeamCity REST API指定多个标记来获取构建?

时间:2016-07-14 20:22:12

标签: rest teamcity teamcity-9.0 teamcity-rest-api

我有一些构建。每个构建都有两个标记。标签显示模块名称和版本。所以标签就像one-module1.2.3two-module4.5.6一样。

我可以这样做:

/httpAuth/app/rest/builds/?locator=tags:one-module,branch:unspecified:any&fields=build(tags(tag))

我会得到这个:

{
  "build": [
    {
      "tags": {
        "tag": [
          {
            "name": "1.2.4"
          },
          {
            "name": "one-module"
          }
        ]
      }
    },
    {
      "tags": {
        "tag": [
          {
            "name": "1.2.3"
          },
          {
            "name": "one-module"
          }
        ]
      }
    }
  ]
}

现在,我希望获得包含代码one-module1.2.4的最新版本。我怎么能这样做?

我试试这个:

/httpAuth/app/rest/builds/?locator=tags:one-module,1.2.4,branch:unspecified:any&fields=build(tags(tag))

但我得到了这个:

Error has occurred during request processing (Bad Request).
Error: jetbrains.buildServer.server.rest.errors.LocatorProcessException: Bad locator syntax: Invalid dimension name :'1.2.4'. Should contain only alpha-numeric symbols or be known one. Details: locator: 'tags:one-module,1.2.4,branch:unspecified:any', at position 16
Invalid request. Check locator is specified correctly.

我有TeamCity版本9.1.6。 TeamCity REST API BuildLocator documentation说:

  

标签: - “,”(逗号) - 构建标签的分隔列表(仅限构建版本)   包含所有指定的标签都返回)

所以,我尝试按这样的2个或更多标签选择构建。这不起作用?

我做错了什么?我如何通过2个或更多标签构建最新版本?

3 个答案:

答案 0 :(得分:2)

我意外地找到了通过两个或更多标签构建的方法。

解决方案:以这种方式使用构建定位器:tags:(one-tag,two-tag,three-tag,etc-tag)

我不确定这是正确的解决方案。如果它是正确的JetBrains只是忘了更新TC REST API的文档。或者它只是TeamCity内部的东西。我在对文档的评论中询问了here

答案 1 :(得分:0)

自Teamcity 10起,您还可以仅列出几个标记子句(或“非”标记子句),例如

http://server/guestAuth/app/rest/builds?locator=defaultFilter:false,tag:sel,not:tag:unres

奇怪的是,我还没有找到一种选择带有多个标签中任何一个的版本的方法。

答案 2 :(得分:0)

以上两种解决方案均适用于获取带有多个标签的内部版本。现在这是旧版:tags:(one-tag,two-tag,three-tag,etc-tag)Current docs建议采用这种方式:tag:one-tag,tag:two-tag

不幸的是,您不能使用多个“ not”标记子句(无论是传统语法还是当前语法)。

如果您尝试在旧式语法中使用多个“ not”标记子句,则会得到不好的结果,即仅排除排除标签之一的版本;如果使用当前语法,则会收到一个400错误的请求,但有以下异常:“定位器仅支持单个'not'维。”