![](/img/trans.png)
[英]How can I get a list of the last build for each Git branch in the TeamCity REST API?
[英]Teamcity REST API get latest successful build on a branch
我正在使用git flow和teamcity作為我的CI服務器。 我想從特定分支上的最新成功構建中提取工件。
我可以使用這個url來獲取分支上的最新版本: http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$branchName$
但如果分支名稱包含/
(例如,git flow names分支feature/%
和release/%
)則失敗。
我試過url編碼/
。 例如,如果$branchName$> == 'release/branchName'
我使用/builds/branch:name:release%2F$branchName$)
。
/builds/branch:name:develop
/builds/branch:name:release%2F$branchName$
。 我沒有得到API錯誤,但api結果為空。
您可以通過將構建定位器放入查詢字符串而不是作為URL的路徑元素的一部分來解決此問題,即,而不是/builds/branch:name:release%2F1.0.1
等,您可以執行/builds?locator=branch:name:release%2F1.0.1
。 返回的數據格式似乎並不相同,但它確實包含內部構建ID,因此您始終可以使用該ID對該確切構建發出第二個請求,例如/builds/id:3332
。
另一點,我沒有親自嘗試過,可以在JetBrains的問題跟蹤器的評論中找到:
我深入研究了一下,發現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
我不知道這是否被認為是一種糟糕的安全措施。
如果沒有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$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.