I'm trying to follow some guidance from this article which describes NuGet and SemVer best practices.
Point #3 states that I should "Use leading zeros in the numerical suffix to auto-increment prereleases" but I am struggling working out how I can zero pad the build.counter
parameter in TeamCity so that I get 0025
instead of 25
.
Does anyone have a mechanism to handle this?
You could write a powershell script like:
function Update-BuildNumber([string]$buildNumber)
{
$VersionComponents = $buildNumber.Split(".")
$buildNumber = ""
foreach($VersionComponent in $VersionComponents)
{
$index = [array]::IndexOf($VersionComponents, $VersionComponent)
if (($index + 1) -eq $VersionComponents.Count)
{
$buildNumber += "00" + $VersionComponent
}
else
{
$buildNumber += $VersionComponent + "."
}
}
Write-Output "##teamcity[buildNumber '$buildNumber']"
}
And call it from a Teamcity build step and pass the parameter %build.number%
something like:
Update-BuildNumber -buildNumber %build.number%
If I were you, I would make use of GitVersion. It includes an option to use a LegacySemVerPadded
version of the generated version number. There are various other alternatives of the generated version number as well.
There is a TeamCity Meta Runner for it here.
GitVersion does the work of calculating the new Semantic Version Number for you, based on the current state of your repository.
Failing that, yeah, do the work elsewhere, in PowerShell, and then use TeamCity Service Messages to change the build number in TeamCity. You can find a PowerShell Module here.
That provides some helper functions for doing just that.
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