Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Teamcity REST API get latest successful build on a branch

Tags:

git

rest

teamcity

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.

like image 957
Chris McKenzie Avatar asked Sep 05 '13 20:09

Chris McKenzie


People also ask

How do you download builds on TeamCity?

What you're actually looking to do is create artifacts in TeamCity. Artifacts are normally a build output which are then attached to the individual build runs so that you can download and review them at a later date. There's a walk through including the creation of build artifacts in You're deploying it wrong!

What is build locator in TeamCity?

BuildLocator Last modified: 26 July 2022. Represents a locator string for filtering Build entities. Examples: id:1 — find build with ID 1 .


2 Answers

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.

like image 199
Keith Pinson Avatar answered Nov 15 '22 19:11

Keith Pinson


Apparently this is a bug in TeamCity as of 8.0.3

It looks like it is being worked on.

like image 25
Chris McKenzie Avatar answered Nov 15 '22 19:11

Chris McKenzie