TeamCity Meta-Runner: Semantic Version Build Number

image

Look at that nice looking SemVer used as a build number in TeamCity. It’s not impossible to get something like that working for you with some script language of choice in a build-runner.
However…I just happened to make mine public, as a meta-runner, and others can benefit from it.

Note: You can download the meta-runner from here (grab the xml file).
Update 2013-10-13: The meta-runner is now part of the JetBrains meta-runner power-pack.

What

The SemVer Build Number meta-runner is a runner based on PowerShell. It can (at the time of this posting):

  • Get version numbers from nuspec (nuget) files.
  • Use manual version numbers (from parameters if you need that). Overrides other methods.
  • Include TeamCity build counter.
  • Include VCS revision.
  • Translate Git commit hash to short hash.
  • Ignore Build MetaData if needed.
  • Logging etc.

Examples

Here’s a SemVer that uses a nuget/nuspec version, teamcity build counter, and the git short hash commit.

[1.4.0]+[169].[4112e01]

image

Here’s another one that uses a manual version, teamcity build counter, and a TFS changeset number.

[0.1.3]+[7].[34]

image

How does it work?

I’ve written about meta-runners before and how to install and build them. Read up here if need that information.

image

1. Manual Version Number

If you use this field it overrides any other methods of getting the version number part of SemVer.
How you supply the information is up to you (manual, previous build step, parse xml file …etc.??)
In the example above it comes from a configuration parameter that prompts the user for it when you execute the build. Looks like this:

image

I created that parameter like this (if you’re interested):

image

2. NuSpec

Sometimes I find it nice to get the version from a .nuspec file if I’m building a nuget package for example.
This field contains the path (relative from checkout dir) to such a file and “lifts” the version from the file if it can.

image

3. Revision Type

[X.Y.Z]+[Build Counter].[Revision]

You can:

  • Skip it – not included
  • Use standard – gets the information from the latest VCS revision included in the build, %build.vcs.number%.
  • Use Short Hash – same as above but it shortens the hash…git style.

4. Ignore MetaData

It just uses [X.Y.Z]

5. Logging

It outputs a bit of logging information for you:

image

HAPPY VERSIONING!!

, , , , , ,

  1. #1 by kjellski on October 8, 2014 - 12:27

    Really usefull, still today, thanks for this!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: