Skip to content

Instantly share code, notes, and snippets.

@EtherZa
Last active June 18, 2019 06:01
Show Gist options
  • Save EtherZa/358f6dada7b838b50506a398684105b8 to your computer and use it in GitHub Desktop.
Save EtherZa/358f6dada7b838b50506a398684105b8 to your computer and use it in GitHub Desktop.
Creates a build number from the current date, build counter and branch name where branch name starts with a story name/number prefix.
# Generated a build number in the format year.month.day.buildCounter-story
# where story is derived from the branch name
#
# Parameters are expected in the following order:
# 1. build counter
# 2. branch name in the format develop | XXXX-ddd
param (
[parameter(Mandatory=$true)] [int]$buildCounter,
[parameter(Mandatory=$true)] [string]$branch
)
try
{
if ($branch -eq "develop")
{
$branch = ""
}
else
{
# strip path root
$branch = [regex]::Replace($branch, "^(?:.+\/)", "")
$match = [regex]::Match($branch, "^([a-zA-Z]{3,4})(?:[-_ ])?(\d+)")
if ($match.Success)
{
$branch = $('-{0}{1}'-f $match.Groups[1].Value, $match.Groups[2].Value)
}
}
$buildNumber = $([DateTime]::UtcNow.ToString('yyyy.M.d') + '.' + $buildCounter + $branch)
Write-Host $("##teamcity[message text='buildNumber: {0}']" -f $buildNumber)
Write-Host $("##teamcity[buildNumber '{0}']" -f $buildNumber)
} Catch {
Write-Host $("##teamcity[message text='{0}' status='ERROR']" -f $_.Exception.Message.Replace("]", "|]"))
[System.Environment]::Exit(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment