HOW TO: Reset build numbers nightly

Moving from our CI server, I wanted to preseve the "SVN revision as build number" scheme everyone is used to. In my old CI server, this was fairly easy because of the way the numbers are added, and the fact that I had to handle artifacts on my own (so they got moved to their own directory, and tagged with the SVN revision, and the actual CI build number was not all that important). If I rebuilt the same SVN revision for some reason (timestamp failing, server config issue, timeout), it would say eg, "Debug r11457 rebuild 2".

In TeamCity, this is obviously a bit different. The build numbers really ARE important. So in order to have both a unique build number (which allows rebuilding the same #) and preserve our old process, I did the following:

The build numbers within each configuration are specified as %system.build.vcs.number%.{0}. This is the SVN revision number, with .x appended, where x is the incrementing TC-generated build number. This means each build shows up as, for example: #11457.2

In order to prevent really huge TC build numbers from making it look totally crazy (eg, #11457.4106), I set up a simple script to reset all the build numbers for all projects every night. This is a relatively simple MSBuild script (though it does require MSBuildCommunityTasks (http://msbuildtasks.tigris.org/):

<!--=======================================================================================
  MSBuild file that resets TeamCity build counters to 1. Meant to be run daily.
===========================================================================================-->
<Project ToolsVersion="3.5" DefaultTarget="ResetCounters" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
    <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
    
    <Target Name="ResetCounters">
        <CreateItem Include="C:\TeamCity\.BuildServer\config\**\*.buildNumbers.properties">
              <Output TaskParameter="Include" ItemName="BuildFiles"/>
        </CreateItem>
        <FileUpdate Files="@(BuildFiles)"
                Multiline="true"
                Singleline="false"
                Regex="next.build=\d+"
                ReplacementText="next.build=1" />
    </Target>
</Project>

and a batch file to simplify invoking:

@echo off
%windir%\Microsoft.NET\Framework\v3.5\MSBuild c:\teamcity\ResetBuildNumbers.build.proj


I run this bat file from task scheduler at midnight every night. TC immediately picks up changes to this file when it starts a build.

For a given project, the first build of the day always starts with .1, and goes up to whatever.. but every day, it always starts over again.

Just thought I'd post in case anyone finds it useful.

1 comment

Starting from version 7.0 TeamCity allows to modify properties by REST API.
See discussion in http://devnet.jetbrains.net/thread/437244

0

Please sign in to leave a comment.