-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert the changes introduced by the flow of the arcade
- Loading branch information
Showing
19 changed files
with
292 additions
and
167 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
param( | ||
[Parameter(Mandatory=$true)][int] $BuildId, | ||
[Parameter(Mandatory=$true)][int] $ChannelId, | ||
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken, | ||
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro.dot.net', | ||
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16' | ||
) | ||
|
||
try { | ||
. $PSScriptRoot\post-build-utils.ps1 | ||
|
||
# Check that the channel we are going to promote the build to exist | ||
$channelInfo = Get-MaestroChannel -ChannelId $ChannelId | ||
|
||
if (!$channelInfo) { | ||
Write-PipelineTelemetryCategory -Category 'PromoteBuild' -Message "Channel with BAR ID $ChannelId was not found in BAR!" | ||
ExitWithExitCode 1 | ||
} | ||
|
||
# Get info about which channel(s) the build has already been promoted to | ||
$buildInfo = Get-MaestroBuild -BuildId $BuildId | ||
|
||
if (!$buildInfo) { | ||
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "Build with BAR ID $BuildId was not found in BAR!" | ||
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 | ||
} | ||
} | ||
} | ||
|
||
Write-Host "Promoting build '$BuildId' to channel '$ChannelId'." | ||
|
||
Assign-BuildToChannel -BuildId $BuildId -ChannelId $ChannelId | ||
|
||
Write-Host 'done.' | ||
} | ||
catch { | ||
Write-Host $_ | ||
Write-PipelineTelemetryError -Category 'PromoteBuild' -Message "There was an error while trying to promote build '$BuildId' to channel '$ChannelId'" | ||
ExitWithExitCode 1 | ||
} |
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Most of the functions in this file require the variables `MaestroApiEndPoint`, | ||
# `MaestroApiVersion` and `MaestroApiAccessToken` to be globally available. | ||
|
||
$ErrorActionPreference = 'Stop' | ||
Set-StrictMode -Version 2.0 | ||
|
||
# `tools.ps1` checks $ci to perform some actions. Since the post-build | ||
# scripts don't necessarily execute in the same agent that run the | ||
# build.ps1/sh script this variable isn't automatically set. | ||
$ci = $true | ||
$disableConfigureToolsetImport = $true | ||
. $PSScriptRoot\..\tools.ps1 | ||
|
||
function Create-MaestroApiRequestHeaders([string]$ContentType = 'application/json') { | ||
Validate-MaestroVars | ||
|
||
$headers = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]' | ||
$headers.Add('Accept', $ContentType) | ||
$headers.Add('Authorization',"Bearer $MaestroApiAccessToken") | ||
return $headers | ||
} | ||
|
||
function Get-MaestroChannel([int]$ChannelId) { | ||
Validate-MaestroVars | ||
|
||
$apiHeaders = Create-MaestroApiRequestHeaders | ||
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}?api-version=$MaestroApiVersion" | ||
|
||
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } | ||
return $result | ||
} | ||
|
||
function Get-MaestroBuild([int]$BuildId) { | ||
Validate-MaestroVars | ||
|
||
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken | ||
$apiEndpoint = "$MaestroApiEndPoint/api/builds/${BuildId}?api-version=$MaestroApiVersion" | ||
|
||
$result = try { return Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } | ||
return $result | ||
} | ||
|
||
function Get-MaestroSubscriptions([string]$SourceRepository, [int]$ChannelId) { | ||
Validate-MaestroVars | ||
|
||
$SourceRepository = [System.Web.HttpUtility]::UrlEncode($SourceRepository) | ||
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken | ||
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions?sourceRepository=$SourceRepository&channelId=$ChannelId&api-version=$MaestroApiVersion" | ||
|
||
$result = try { Invoke-WebRequest -Method Get -Uri $apiEndpoint -Headers $apiHeaders | ConvertFrom-Json } catch { Write-Host "Error: $_" } | ||
return $result | ||
} | ||
|
||
function Assign-BuildToChannel([int]$BuildId, [int]$ChannelId) { | ||
Validate-MaestroVars | ||
|
||
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken | ||
$apiEndpoint = "$MaestroApiEndPoint/api/channels/${ChannelId}/builds/${BuildId}?api-version=$MaestroApiVersion" | ||
Invoke-WebRequest -Method Post -Uri $apiEndpoint -Headers $apiHeaders | Out-Null | ||
} | ||
|
||
function Trigger-Subscription([string]$SubscriptionId) { | ||
Validate-MaestroVars | ||
|
||
$apiHeaders = Create-MaestroApiRequestHeaders -AuthToken $MaestroApiAccessToken | ||
$apiEndpoint = "$MaestroApiEndPoint/api/subscriptions/$SubscriptionId/trigger?api-version=$MaestroApiVersion" | ||
Invoke-WebRequest -Uri $apiEndpoint -Headers $apiHeaders -Method Post | Out-Null | ||
} | ||
|
||
function Validate-MaestroVars { | ||
try { | ||
Get-Variable MaestroApiEndPoint | Out-Null | ||
Get-Variable MaestroApiVersion | Out-Null | ||
Get-Variable MaestroApiAccessToken | Out-Null | ||
|
||
if (!($MaestroApiEndPoint -Match '^http[s]?://maestro-(int|prod).westus2.cloudapp.azure.com$')) { | ||
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiEndPoint is not a valid Maestro URL. '$MaestroApiEndPoint'" | ||
ExitWithExitCode 1 | ||
} | ||
|
||
if (!($MaestroApiVersion -Match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$')) { | ||
Write-PipelineTelemetryError -Category 'MaestroVars' -Message "MaestroApiVersion does not match a version string in the format yyyy-MM-DD. '$MaestroApiVersion'" | ||
ExitWithExitCode 1 | ||
} | ||
} | ||
catch { | ||
Write-PipelineTelemetryError -Category 'MaestroVars' -Message 'Error: Variables `MaestroApiEndPoint`, `MaestroApiVersion` and `MaestroApiAccessToken` are required while using this script.' | ||
Write-Host $_ | ||
ExitWithExitCode 1 | ||
} | ||
} |
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
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
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
Oops, something went wrong.