Teamcity REST APIs get last successful build on branch

I use git thread with teamcity as my CI server. I would like to pull artifacts from the last successful build on a specific branch.

I can use this url to get the latest build on the branch: http://$teamcity$/httpAuth/app/rest/buildTypes/name:$BuildTypeName$/builds/branch:name:$branchName$

but it fails if the branch name contains / (e.g. git thread name branches feature/% and release/% ).

I tried url / encoding. For example, if $branchName$> == 'release/branchName' I use /builds/branch:name:release%2F$branchName$) .

  • works - /builds/branch:name:develop
  • fails - /builds/branch:name:release%2F$branchName$ .

I am not getting an API error, but the api result is empty.

+9
git rest teamcity
source share
3 answers

You can get around this by placing your assembly locator in the query string, and not as part of the URL path element, i.e. instead of /builds/branch:name:release%2F1.0.1 or the like, you can do /builds?locator=branch:name:release%2F1.0.1 . The format of the returned data is not the same, but it includes an internal assembly identifier, so you can always make a second request for this exact assembly using this identifier, for example. /builds/id:3332 .

Another point that I personally have not tried is on this comment from the JetBrains tracker:

I delved into this a bit and found that versions of Tomcat version 6.0.10 and newer no longer accept encoded slashes and backslashes in path elements by default. This behavior can be changed by changing two properties of the Tomcat server (found at 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.

+6
source share

Apparently this is a bug in TeamCity from 8.0.3

It looks like it works.

+3
source share

The following will not work without the correction proposed by Keith:

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

But the following will work since Tomcat allows escaped slashes in query parameters:

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

All Articles