2019-07-27 12:35:24 +00:00
|
|
|
param(
|
2019-06-28 13:15:43 +00:00
|
|
|
[Parameter(Mandatory=$true)][string] $SourceRepo,
|
|
|
|
[Parameter(Mandatory=$true)][int] $ChannelId,
|
2019-07-27 12:35:24 +00:00
|
|
|
[Parameter(Mandatory=$true)][string] $MaestroApiAccessToken,
|
|
|
|
[Parameter(Mandatory=$false)][string] $MaestroApiEndPoint = "https://maestro-prod.westus2.cloudapp.azure.com",
|
|
|
|
[Parameter(Mandatory=$false)][string] $MaestroApiVersion = "2019-01-16"
|
2019-06-28 13:15:43 +00:00
|
|
|
)
|
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
. $PSScriptRoot\post-build-utils.ps1
|
2019-06-28 13:15:43 +00:00
|
|
|
|
|
|
|
# Get all the $SourceRepo subscriptions
|
2019-07-11 12:25:27 +00:00
|
|
|
$normalizedSourceRepo = $SourceRepo.Replace('dnceng@', '')
|
2019-07-27 12:35:24 +00:00
|
|
|
$subscriptions = Get-MaestroSubscriptions -SourceRepository $normalizedSourceRepo -ChannelId $ChannelId
|
2019-06-28 13:15:43 +00:00
|
|
|
|
|
|
|
if (!$subscriptions) {
|
2019-07-11 12:25:27 +00:00
|
|
|
Write-Host "No subscriptions found for source repo '$normalizedSourceRepo' in channel '$ChannelId'"
|
2019-07-27 12:35:24 +00:00
|
|
|
ExitWithExitCode 0
|
2019-06-28 13:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$subscriptionsToTrigger = New-Object System.Collections.Generic.List[string]
|
|
|
|
$failedTriggeredSubscription = $false
|
|
|
|
|
|
|
|
# Get all enabled subscriptions that need dependency flow on 'everyBuild'
|
|
|
|
foreach ($subscription in $subscriptions) {
|
|
|
|
if ($subscription.enabled -and $subscription.policy.updateFrequency -like 'everyBuild' -and $subscription.channel.id -eq $ChannelId) {
|
2019-07-27 12:35:24 +00:00
|
|
|
Write-Host "Should trigger this subscription: $subscription.id"
|
2019-06-28 13:15:43 +00:00
|
|
|
[void]$subscriptionsToTrigger.Add($subscription.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($subscriptionToTrigger in $subscriptionsToTrigger) {
|
|
|
|
try {
|
2019-07-27 12:35:24 +00:00
|
|
|
Write-Host "Triggering subscription '$subscriptionToTrigger'."
|
2019-06-28 13:15:43 +00:00
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
Trigger-Subscription -SubscriptionId $subscriptionToTrigger
|
2019-06-28 13:15:43 +00:00
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
Write-Host "done."
|
2019-06-28 13:15:43 +00:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
Write-Host "There was an error while triggering subscription '$subscriptionToTrigger'"
|
|
|
|
Write-Host $_
|
|
|
|
Write-Host $_.ScriptStackTrace
|
|
|
|
$failedTriggeredSubscription = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 12:35:24 +00:00
|
|
|
if ($subscriptionsToTrigger.Count -eq 0) {
|
|
|
|
Write-Host "No subscription matched source repo '$normalizedSourceRepo' and channel ID '$ChannelId'."
|
|
|
|
}
|
|
|
|
elseif ($failedTriggeredSubscription) {
|
2019-06-28 13:15:43 +00:00
|
|
|
Write-Host "At least one subscription failed to be triggered..."
|
|
|
|
ExitWithExitCode 1
|
|
|
|
}
|
2019-07-27 12:35:24 +00:00
|
|
|
else {
|
|
|
|
Write-Host "All subscriptions were triggered successfully!"
|
|
|
|
}
|