We are using TeamCity as a CI server and we've been thinking how to implement a method for versioning our releases that is safe (i.e. minimal opportunity for human error) but also that requires the least effort possible. So far the following seems the most logical:
We believe the benefit of doing things this way is should we need to do a fix of an old release then the version number will be correct and TeamCity can simply work with the old version file, and incrementing the build count as usual. This does make the assumption that we are updating our major/minor/patch versions correctly. This will hopefully work nicely with the soon to be released feature of TeamCity 7.1 that lets you choose which branch to build via the custom build dialog.
From what I've already read so far these sort of operations should be possible in TeamCity but we're looking for the easiest root to get this fixed as we're only a two-man outfit and we can't afford to invest large amounts of time into becoming experts at Nant or powershell only to find it might not do what we want.
So I guess to sum up my questions are as follows:
Any help is greatly appreciated.
For your first question: yes, it's possible:
Sorry but i can't answer for your second question because i don't know any appropriate tools for windows. On linux i would use bash.
Add a build step using the PowerShell runner type
Set the Script field to Source code
In the ScriptSource field enter the following:
# Get AssemblyInfo file's contents
$file = "GlobalAssemblyInfo.cs"
$contents = get-content $file -Raw
# Regex to get the version number from AssemblyInfo file contents
$regex = new-object System.Text.RegularExpressions.Regex ('(^\s*\[\s*assembly\s*:\s*((System\s*\.)?\s*Reflection\s*\.)?\s*AssemblyVersion(Attribute)?\s*\(\s*@?\")(?<version>.*?)(\"\s*\)\s*\])', [System.Text.RegularExpressions.RegexOptions]::MultiLine)
# Get the version number
$version = $regex.Match($contents).Groups["version"].Value
# Update TeamCity buildNumber parameter using stdout
echo "##teamcity[buildNumber '$($version)']"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With