Skip to content

Instantly share code, notes, and snippets.

@dealproc
Last active August 29, 2015 14:25
Show Gist options
  • Save dealproc/eb1a546dd591cc6ca5e9 to your computer and use it in GitHub Desktop.
Save dealproc/eb1a546dd591cc6ca5e9 to your computer and use it in GitHub Desktop.
Gist on how i setup teamcity, based on octopus deploy's script.
# These are project build parameters in TeamCity
# Depending on the branch, we will use different major/minor versions
$majorMinorVersionMaster = "%system.MajorMinorVersion.Master%"
#$majorMinorVersionMaster = "1.9.0"
# TeamCity's auto-incrementing build counter; ensures each build is unique
$buildCounter = "%build.counter%"
#$buildCounter = "999"
# This gets the name of the current Git branch.
$branch = "%teamcity.build.branch%"
#$branch = "refs/heads/release-2.4.88"
# 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 "Branch: $branch"
if ($branch -eq "master")
{
$buildNumber = "${majorMinorVersionMaster}.${buildCounter}"
$buildInfo = "${majorMinorVersionMaster}.${buildCounter}"
$buildSeries = $majorMinorVersionMaster.Substring(0, $majorMinorVersionMaster.IndexOf('.')) + '.0.0.0'
}
elseif ($branch -match "(\d+\.)(\d+\.)(\d+)$")
{
$buildNumber = "${branch}.${buildCounter}"
$buildInfo = "${branch}.${buildCounter}"
$buildSeries = $branch.Substring(0, $branch.IndexOf('.')) + '.0.0.0'
}
elseif ($branch -match "release-.*")
{
$specificRelease = ($branch -replace 'release-(.*)','$1')
$buildNumber = "${specificRelease}.${buildCounter}"
$buildInfo = "${specificRelease}.${buildCounter}"
$buildSeries = $specificRelease.Substring(0, $specificRelease.IndexOf('.')) + '.0.0.0'
}
else
{
# If the branch starts with "feature-", just use the feature name
$branch = $branch.replace("feature-", "")
$buildNumber = "${majorMinorVersionMaster}.${buildCounter}"
$buildInfo = "${majorMinorVersionMaster}.${buildCounter}-${branch}"
$buildSeries = $majorMinorVersionMaster.Substring(0, $majorMinorVersionMaster.IndexOf('.')) + '.0.0.0'
}
Write-Host "##teamcity[buildNumber '$buildNumber']"
Write-Host "##teamcity[setParameter name='system.Version' value='$buildNumber']"
Write-Host "##teamcity[setParameter name='system.BuildInfo' value='$buildInfo']"
Write-Host "##teamcity[setParameter name='system.BuildSeries' value='$buildSeries']"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment