[英]Teamcity REST API get latest successful build on a branch
I'm using git flow with teamcity as my CI server. 我正在使用git flow和teamcity作为我的CI服务器。 I'd like to pull artifacts from the latest successful build on a particular branch. 我想从特定分支上的最新成功构建中提取工件。
I can use this url to get the latest build on a branch: http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$branchName$
我可以使用这个url来获取分支上的最新版本: http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$branchName$
but it fails if the branch name contains /
(eg, git flow names branches feature/%
and release/%
). 但如果分支名称包含/
(例如,git flow names分支feature/%
和release/%
)则失败。
I've tried url encoding the /
. 我试过url编码/
。 For example, if $branchName$> == 'release/branchName'
I use /builds/branch:name:release%2F$branchName$)
. 例如,如果$branchName$> == 'release/branchName'
我使用/builds/branch:name:release%2F$branchName$)
。
/builds/branch:name:develop
works - /builds/branch:name:develop
/builds/branch:name:release%2F$branchName$
. 失败 - /builds/branch:name:release%2F$branchName$
。 I don't get an API error, but the api result is empty. 我没有得到API错误,但api结果为空。
You can work around this by putting your build locator into a query string rather than as part of the path element of the URL, ie instead of /builds/branch:name:release%2F1.0.1
or the like, you could do /builds?locator=branch:name:release%2F1.0.1
. 您可以通过将构建定位器放入查询字符串而不是作为URL的路径元素的一部分来解决此问题,即,而不是/builds/branch:name:release%2F1.0.1
等,您可以执行/builds?locator=branch:name:release%2F1.0.1
。 The format of the data coming back does not seem to be the same, but it does include the internal build ID, so you can always make a second request for that exact build using that ID, eg /builds/id:3332
. 返回的数据格式似乎并不相同,但它确实包含内部构建ID,因此您始终可以使用该ID对该确切构建发出第二个请求,例如/builds/id:3332
。
Another point, which I have not personally tried, is found on this comment from JetBrains' issue tracker: 另一点,我没有亲自尝试过,可以在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. 我深入研究了一下,发现Tomcat版本6.0.10和更新版本默认不再接受路径元素中的编码斜杠和反斜杠。 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 ): 可以通过更改两个Tomcat服务器属性(在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
I do not know if this is considered a bad security practice. 我不知道这是否被认为是一种糟糕的安全措施。
Apparently this is a bug in TeamCity as of 8.0.3 显然,这是TeamCity从8.0.3开始的一个错误
It looks like it is being worked on. 看起来它正在被开发。
The following will fail without the fix Keith suggested: 如果没有Keith建议的修复,以下内容将失败:
http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$urlEncodedBranchName$
But the following will work as Tomcat does allow escaped slashes in query parameters: 但是以下内容将起作用,因为Tomcat允许在查询参数中使用转义斜杠:
http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds?branch:name:$urlEncodedBranchName$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.