Teamcity REST API 获取分支上最新成功构建

10
我正在使用git flow和teamcity作为我的CI服务器。我想从特定分支上最新的成功构建中拉取构件。
我可以使用此URL获取分支上的最新构建:http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$branchName$,但是如果分支名称包含/(例如,git flow将分支命名为feature/%release/%),则会失败。
我尝试过对/进行URL编码。例如,如果$branchName$> == 'release/branchName',我会使用/builds/branch:name:release%2F$branchName$)
  • 正常工作 - /builds/branch:name:develop
  • 无法工作 - /builds/branch:name:release%2F$branchName$.
我没有收到API错误,但API结果为空。
3个回答

10
您可以通过将构建定位器放入查询字符串而不是URL路径元素的一部分来解决此问题,例如,您可以使用/builds?locator=branch:name:release%2F1.0.1而不是/builds/branch:name:release%2F1.0.1等。返回数据的格式似乎不同,但它包括内部构建ID,因此您始终可以使用该ID对该精确构建进行第二次请求,例如/builds/id:3332
另外一个点,我个人没有尝试过,可以在JetBrains的问题跟踪器这篇评论中找到。

I delved into this a bit and discovered that Tomcat versions 6.0.10 and newer by default don't accept encoded slashes and backslashes in path elements anymore. This behavior can be changed by changing two Tomcat server properties (found on http://tomcat.apache.org/security-6.html#Fixed_in_Apache_Tomcat_6.0.10):

-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true
我不知道这是否被视为一种不良的安全实践。

3

显然这是TeamCity在8.0.3版本中存在的漏洞

看起来正在修复中。


1
截至9.0.1仍存在问题。 - Keith Pinson

1
以下代码如果没有 Keith 建议的修复将会失败:
http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$urlEncodedBranchName$

但是以下的方法可以起作用,因为Tomcat允许在查询参数中使用转义斜杠:

http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds?branch:name:$urlEncodedBranchName$

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接