Skip to content

Instantly share code, notes, and snippets.

@sqldeployhelmet
Created January 30, 2020 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sqldeployhelmet/550e6532fc78a8f014bc950f27e0c6c7 to your computer and use it in GitHub Desktop.
Save sqldeployhelmet/550e6532fc78a8f014bc950f27e0c6c7 to your computer and use it in GitHub Desktop.
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
Copy link

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