How can I label my build with revision number and not the GUID (in TeamCity)?

11,527

Solution 1

As Lasse V. Karlsen mentioned those numerical revision numbers are local-clone specific and can be different for each clone. They're really not suitable for versioning -- you could reclone the same repo and get different revision numbers.

At the very least include the node id also creating something like 0.0.12-6ec760554f2b then you still get sortable release artifacts but are still firmly identifying your release.

If you're using numeric tags to tag releases there's a particularly nice option:

% hg log -r tip --template '{latesttag}.{latesttagdistance}'

which, if the most recent tag on that clone was called 1.0.1 and was 84 commits ago gives a value like:

1.0.1.84

Since you can have different heads that are 84 commits away from a tag in different repos you should still probably include the node id like:

% hg log -r tip --template '{latesttag}.{latesttagdistance}-{node|short}'

giving:

1.0.1.84-ec760554f2b

which makes a great version string.

Solution 2

The best and easiest way to see rev. number in TeamCity build number is to use Build Script Interaction with TeamCity. Namely, it has a possibility to set Build Number.

So, add to your project a new very first build step Command Line with following Command Executable

for /f %%i in ('c:\tortoisehg\hg id -n') do echo ##teamcity[buildNumber '%%i']

And you will get the Mercurial revision number as a label for your every build.

Of course you can change the command in quotes to anything you wish.

I believe my answer is way more correct than the accepted one.

EDIT:

Also you can do the same via MSBuild task rather than Command Executable. Have a MSBuild project file with following code, setup TeamCity to run it as first step, and it will alter its global variable buildNumber:

<Message Text="##teamcity[buildNumber '$(CurrentVersion)']" Importance="High" />

Where CurrentVersion is a string containing full version (for example "1.0.56.20931").

Solution 3

hg id produces the hash (6ec760554f2b), hg id -n produces the local revision number (12).

(Note this is an answer purely from the hg side, how you then get that into TeamCity, I don't know, as I've never used it.)

Solution 4

I managed to use it in Teamcity using a workaround:

    <Exec Command="hg log -r tip --template {latesttag}.{latesttagdistance} > $(BuildAgentTempDir)\version.txt"/>
    <ReadLinesFromFile File="$(BuildAgentTempDir)\version.txt">
        <Output TaskParameter="Lines" ItemName="versionInfo"/>
    </ReadLinesFromFile>
    <TeamCitySetBuildNumber BuildNumber="@(versionInfo)-{build.number}" />

If you see the MSBuild task "TeamCitySetBuildNumber" I'm using the "{build.number}" variable because it substitutes this with what you set in the build number originally. I used %build.vcs.number% in my original settings (in the Web UI) and the result is just what Ry4an wrote above!

Hope it works for you!

Solution 5

When I used to use Subversion I used to do something similar in TeamCity. The format was:

{Major}.{Minor}.{TeamCity Build No.}.{Subversion Revision No.}

This allowed me to look at an assembly and see which build it came from on TeamCity and the revision number from subversion.

I have now moved to Git which has put me in the same situation as you. After playing with various ideas I have come to the conclusion that I don't actually need the revision, the build is good enough. Because TeamCity is such a powerful tool, all you need is the build number, given the build number you can look at the build history and determine the revision from that.

{Major}.{Minor}.{Macro}.{TeamCity Build No.}

Additionally you can get TeamCity to label your repository with the build number allowing you to look up a given build in your source control.

Share:
11,527
Tomas Pajonk
Author by

Tomas Pajonk

Working on Vehicle Routing and Scheduling applications.

Updated on July 27, 2022

Comments

  • Tomas Pajonk
    Tomas Pajonk almost 2 years

    I am trying to do "continuous integration" with TeamCity. I would like to label my builds in a incremental way and the GUID provided by the VCS is not as usefull as a simple increasing number. I would like the number to actually match the revision in number in Mercurial.

    My state of affairs:

    alt text

    Mercurial info:

    alt text

    I would like the build to be labeled 0.0.12 rather than the GUID.

    Would someone be so kind and save me hours of trying to figure this out ?