2019-06-28 13:15:43 +00:00
|
|
|
param(
|
|
|
|
[Parameter(Mandatory=$true)][int] $BuildId,
|
|
|
|
[Parameter(Mandatory=$true)][int] $ChannelId,
|
2019-07-27 12:35:24 +00:00
|
|
|
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken,
|
2023-12-01 16:57:58 +00:00
|
|
|
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net',
|
2019-11-22 13:41:58 +00:00
|
|
|
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16'
|
2019-06-28 13:15:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
try {
|
2019-11-22 13:41:58 +00:00
|
|
|
. $PSScriptRoot\post-build-utils.ps1
|
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
# Check that the channel we are going to promote the build to exist
|
|
|
|
$channelInfo = Get-MaestroChannel -ChannelId $ChannelId
|
2019-06-28 13:15:43 +00:00
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
if (!$channelInfo) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryCategory -Category 'PromoteBuild' -Message "Channel with BAR ID $ChannelId was not found in BAR!"
|
2019-07-27 12:35:24 +00:00
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|
2019-06-28 13:15:43 +00:00
|
|
|
|
2020-01-30 13:35:10 +00:00
|
|
|
# Get info about which channel(s) the build has already been promoted to
|
2019-07-27 12:35:24 +00:00
|
|
|
$buildInfo = Get-MaestroBuild -BuildId $BuildId
|
|
|
|
|
2019-06-28 13:15:43 +00:00
|
|
|
if (!$buildInfo) {
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "Build with BAR ID $BuildId was not found in BAR!"
|
2019-06-28 13:15:43 +00:00
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Find whether the build is already assigned to the channel or not
|
|
|
|
if ($buildInfo.channels) {
|
|
|
|
foreach ($channel in $buildInfo.channels) {
|
|
|
|
if ($channel.Id -eq $ChannelId) {
|
|
|
|
Write-Host "The build with BAR ID $BuildId is already on channel $ChannelId!"
|
|
|
|
ExitWithExitCode 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
Write-Host "Promoting build '$BuildId' to channel '$ChannelId'."
|
|
|
|
|
|
|
|
Assign-BuildToChannel -BuildId $BuildId -ChannelId $ChannelId
|
2019-06-28 13:15:43 +00:00
|
|
|
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-Host 'done.'
|
2019-06-28 13:15:43 +00:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-Host $_
|
2019-11-22 13:41:58 +00:00
|
|
|
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to promote build '$BuildId' to channel '$ChannelId'"
|
|
|
|
ExitWithExitCode 1
|
2019-06-28 13:15:43 +00:00
|
|
|
}
|