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.
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.
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.
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:
I created that parameter like this (if you’re interested):
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.
3. Revision Type
- 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]
It outputs a bit of logging information for you: