| 1 |
param( |
| 2 |
[Parameter(Mandatory=$true)][string] $SourceRepo, |
| 3 |
[Parameter(Mandatory=$true)][int] $ChannelId, |
| 4 |
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken, |
| 5 |
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = 'https://maestro-prod.westus2.cloudapp.azure.com', |
| 6 |
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = '2019-01-16' |
| 7 |
) |
| 8 |
|
| 9 |
try { |
| 10 |
. $PSScriptRoot\post-build-utils.ps1 |
| 11 |
|
| 12 |
# Get all the $SourceRepo subscriptions |
| 13 |
$normalizedSourceRepo = $SourceRepo.Replace('dnceng@', '') |
| 14 |
$subscriptions = Get-MaestroSubscriptions -SourceRepository $normalizedSourceRepo -ChannelId $ChannelId |
| 15 |
|
| 16 |
if (!$subscriptions) { |
| 17 |
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message "No subscriptions found for source repo '$normalizedSourceRepo' in channel '$ChannelId'" |
| 18 |
ExitWithExitCode 0 |
| 19 |
} |
| 20 |
|
| 21 |
$subscriptionsToTrigger = New-Object System.Collections.Generic.List[string] |
| 22 |
$failedTriggeredSubscription = $false |
| 23 |
|
| 24 |
# Get all enabled subscriptions that need dependency flow on 'everyBuild' |
| 25 |
foreach ($subscription in $subscriptions) { |
| 26 |
if ($subscription.enabled -and $subscription.policy.updateFrequency -like 'everyBuild' -and $subscription.channel.id -eq $ChannelId) { |
| 27 |
Write-Host "Should trigger this subscription: ${$subscription.id}" |
| 28 |
[void]$subscriptionsToTrigger.Add($subscription.id) |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
foreach ($subscriptionToTrigger in $subscriptionsToTrigger) { |
| 33 |
try { |
| 34 |
Write-Host "Triggering subscription '$subscriptionToTrigger'." |
| 35 |
|
| 36 |
Trigger-Subscription -SubscriptionId $subscriptionToTrigger |
| 37 |
|
| 38 |
Write-Host 'done.' |
| 39 |
} |
| 40 |
catch |
| 41 |
{ |
| 42 |
Write-Host "There was an error while triggering subscription '$subscriptionToTrigger'" |
| 43 |
Write-Host $_ |
| 44 |
Write-Host $_.ScriptStackTrace |
| 45 |
$failedTriggeredSubscription = $true |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if ($subscriptionsToTrigger.Count -eq 0) { |
| 50 |
Write-Host "No subscription matched source repo '$normalizedSourceRepo' and channel ID '$ChannelId'." |
| 51 |
} |
| 52 |
elseif ($failedTriggeredSubscription) { |
| 53 |
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message 'At least one subscription failed to be triggered...' |
| 54 |
ExitWithExitCode 1 |
| 55 |
} |
| 56 |
else { |
| 57 |
Write-Host 'All subscriptions were triggered successfully!' |
| 58 |
} |
| 59 |
} |
| 60 |
catch { |
| 61 |
Write-Host $_.ScriptStackTrace |
| 62 |
Write-PipelineTelemetryError -Category 'TriggerSubscriptions' -Message $_ |
| 63 |
ExitWithExitCode 1 |
| 64 |
} |