-
-
Save ducke/ab7e923df7b3bea41dcf to your computer and use it in GitHub Desktop.
Powershell script for TeamCity that creates and deploys a release on Octopus Deploy based on the current branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Is-Default-Branch { | |
return "%teamcity.build.branch.is_default%" -eq "true" | |
} | |
function Build-Arguments { | |
if (Is-Default-Branch) { | |
$releaseNumber = "%octopus.master.releaseNumber%" | |
$deployTo = "%octopus.master.deployTo%" | |
$packageVersion = "%octopus.master.packageVersion%" | |
} | |
else { | |
$releaseNumber = "%octopus.release.releaseNumber%" | |
$deployTo = "%octopus.release.deployTo%" | |
$packageVersion = "%octopus.release.packageVersion%" | |
} | |
$args = @() | |
$args += "create-release" | |
$args += "--server=%octopus.url%" | |
$args += "--apikey=%octopus.apikey%" | |
$args += "--project=%octopus.project%" | |
$args += "--version=$releaseNumber" | |
$args += "--deployto=$deployTo" | |
$args += "--packageversion=$packageVersion" | |
$args += "--force" | |
$args += "--enableservicemessages" | |
$args += "--progress" | |
if ("%octopus.waitForDeployment%" -eq "true") { | |
$args += "--waitfordeployment" | |
} | |
return $args | |
} | |
function Secure-Sensitive-Data { | |
return $input -Replace "(--apikey)(=.*)$", '$1 SECRET' | |
} | |
$octo = Join-Path -Path "%teamcity.tool.octopus%" -ChildPath "octo.exe" | |
$args = Build-Arguments | |
Write-Host "--" | |
Write-Host "Executing octo.exe..." | |
Write-Host "source : $octo" | |
Write-Host "arguments:", ($args | Secure-Sensitive-Data) | |
& $octo $args | Out-String | |
if (-Not $?) { | |
Exit $LASTEXITCODE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment