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{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 (

  MSBuild file that resets TeamCity build counters to 1. Meant to be run daily.
<Project ToolsVersion="3.5" DefaultTarget="ResetCounters" xmlns="">
    <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
    <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
    <Target Name="ResetCounters">
        <CreateItem Include="C:\TeamCity\.BuildServer\config\**\*">
              <Output TaskParameter="Include" ItemName="BuildFiles"/>
        <FileUpdate Files="@(BuildFiles)"
                ReplacementText="" />

and a batch file to simplify invoking:

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

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


Please sign in to leave a comment.