Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PS Code for Dynamically setting a build number.
# The build number format is YYYY.MM.B (Year.Month.BuildCounter)
$MonthCounter = ([DateTime]::Now.Month).ToString().PadLeft(2, "0")
$YearCounter = ([DateTime]::Now.Date.Year).ToString()
$DayCounter = ([DateTime]::Now.Day).ToString().PadLeft(2, "0")
$TimeCounter = ([DateTime]::Now.Hour).ToString().PadLeft(2, "0")
$MinuteCounter = ([DateTIme]::Now.Minute).ToString().PadLeft(2, "0")
$counter = "$YearCounter.$MonthCounter.$DayCounter.$TimeCounter" + $MinuteCounter
<# writing the build number back to the host to overwrite the variable for Team City #>
Write-Host "##teamcity[buildNumber '$counter']"
@logicalextreme

This comment has been minimized.

Copy link

logicalextreme commented Feb 13, 2020

heads-up! you could do this with one line

<# writing the build number back to the host to overwrite the variable for Team City #>
Write-Host ("##teamcity[buildNumber '{0}']" -f [datetime]::Now.ToString("yyyy.MM.dd.HHmm"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.