Skip to content

Instantly share code, notes, and snippets.

@markryd
Created September 22, 2015 05:07
Show Gist options
  • Select an option

  • Save markryd/5fee7fef64864fb8934b to your computer and use it in GitHub Desktop.

Select an option

Save markryd/5fee7fef64864fb8934b to your computer and use it in GitHub Desktop.
Set release numbers in Teamcity
# TeamCity's auto-incrementing build counter; ensures each build is unique
$buildNumber = "%build.number%"
$deploymentProject = "%deploymentTarget%"
# This gets the name of the current Git branch.
$branch = "%teamcity.build.branch%"
# Sometimes the branch will be a full path, e.g., 'refs/heads/master'.
# If so we'll base our logic just on the last part.
if ($branch.Contains("/"))
{
$branch = $branch.substring($branch.lastIndexOf("/")).trim("/")
}
Write-Host "Original Branch Name: $branch"
if ($branch -ne "master" -and $branch -ne "<default>")
{
# If the branch starts with "feature-", just use the feature name
$branch = $branch.Replace("feature-", "")
# If the branch starts with four digits assume a card number
if ($branch -match '^[0-9]{4}.*$')
{
$branch = "Card$branch"
}
# NuGet is a sensitive creature, offended by non-alphanumeric characters and version specifiers
$branch = ($branch -ireplace '[^A-Z0-9]*','').Trim()
# NuGet also shys away from the pre-release tag being empty or the first character a number
if (($branch.Length -eq 0) -or ($branch -match '^[0-9].*$'))
{
$branch = "Branch$branch"
}
# NuGet has a 20-character limit on pre-release version strings
if ($branch.Length -gt 20)
{
$branch = $branch.Substring(0, 20)
Write-Host "Branch trimmed for pre-release tag to: $branch"
}
$buildNumber = "${buildNumber}-${branch}"
# We only want to deploy to Development if we're on master or test
$deploymentProject = ""
if ($branch.ToUpperInvariant() -eq "TEST")
{
$deploymentProject = "Test"
}
Write-Host "Cleaned Branch Name: $branch"
}
Write-Host "##teamcity[buildNumber '$buildNumber']"
Write-Host "##teamcity[setParameter name='deploymentTarget' value='$deploymentProject']"
@markryd

markryd commented Sep 22, 2015

Copy link
Copy Markdown
Author

@markryd

markryd commented Sep 22, 2015

Copy link
Copy Markdown
Author

Also contains some stuff to trigger automatic deployments at the end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment