9
votes

I'm using git flow with teamcity as my CI server. 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$

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

I've tried url encoding the /. 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 don't get an API error, but the api result is empty.

3

3 Answers

7
votes

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, i.e. instead of /builds/branch:name:release%2F1.0.1 or the like, you could do /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, e.g. /builds/id:3332.

Another point, which I have not personally tried, is found on this comment from JetBrains' issue tracker:

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

I do not know if this is considered a bad security practice.

3
votes

Apparently this is a bug in TeamCity as of 8.0.3

It looks like it is being worked on.

0
votes

The following will fail without the fix Keith suggested:

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:

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