Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Team City - Get Revision Number of Last Successful Build

Tags:

svn

teamcity

Here is what I want to accomplish.

When a Team City build runs, I want to call out to my exe and provide the current Svn revision number, and also the revision number of the last successful build if there is one

I have already written an exe that can take these arguments and then get the commits from svn between those two revision numbers in order to build a basic "change log". The exe then writes to stdout in order to set a Team City build parameter with the change log - that parameter is used later on in the build.

I have established that the team city parameter for the current revision number is: build.vcs.number

How can I get the equivalent for the last successful build?

I am open to the idea of my exe calling back into a Team City API to get the last successful build details. If such a thing is possible, please can someone provide details around that i.e the API calls required etc?

like image 506
Darrell Avatar asked Sep 27 '22 20:09

Darrell


1 Answers

I've done this before to automate release notes from TFS by getting the commit comments between two revisions.

There's two routes to achieving this, depending on if you use the build.vcs.number as part of your version number - If you do then you'd be able to obtain the build number of the previous build by querying the API. You can browse the API in a regular browser and just need to substitute the buildTypeId into the URL to see the results.

http://tcserver/httpAuth/api/buildTypes/id:YOUR_ID_HERE/builds?count=1

You could query this dataset and extract the attribute value and break it apart depending on how you might be using it.

So the general makeup of your build configuration in this case would be

Step 1. Call API and parse previous changeset number from xml attribute

Step 2. Call exe with build.vcs.number and %PARSED_PARAMETER%

Step 3. Do your build

If you are not using this to form part of your version number then you'll need a step to save this value to a variable, that should be executed at the end of your build. I've found that this has to be done by posting the value to the API so that it persists in TeamCity, otherwise this becomes quite transient.

Perform an HTTP PUT operation to the url of your parameter and you can update the value. The url of you parameter would look something like this

http://tcserver/httpAuth/app/rest/buildTypes/id:YOUR_ID_HERE/parameters/PARAMATER_NAME

More details can be found here - TeamCity Documentation

So the general makeup of your build configuration in this case would be

Step 1. Call exe with build.vcs.number and %YOUR_PARAMETER%

Step 2. Do your build

Step 3. Update YOUR_PARAMETER through API call

I've got code to update parameters through the API using PowerShell if it helps, but can't assume you're on a windows install. Let me know if it's of any use.

Hope this helps.

like image 178
Evolve Software Ltd Avatar answered Dec 06 '22 09:12

Evolve Software Ltd