From b3ffaa4b19b82a1af946641e60280ba267dd668e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20De=20Smet?= Date: Mon, 29 Aug 2022 13:18:43 +0200 Subject: [PATCH] Use template parameters to start triggers post deployment --- .../PrePostDeploymentScript.Ver2.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/SamplesV2/ContinuousIntegrationAndDelivery/PrePostDeploymentScript.Ver2.ps1 b/SamplesV2/ContinuousIntegrationAndDelivery/PrePostDeploymentScript.Ver2.ps1 index 216da977..516e75f3 100644 --- a/SamplesV2/ContinuousIntegrationAndDelivery/PrePostDeploymentScript.Ver2.ps1 +++ b/SamplesV2/ContinuousIntegrationAndDelivery/PrePostDeploymentScript.Ver2.ps1 @@ -457,7 +457,8 @@ function Compare-TriggerAdditionalProperties { } function Update-TriggerTemplate { - param([string]$templateJson, + param( + [string]$templateJson, [PSCustomObject]$templateParameters ) @@ -495,7 +496,8 @@ $triggersDeployed = Get-SortedTriggers -DataFactoryName $DataFactoryName -Resour if ($PreDeployment -eq $true) { #Stop trigger only if there is change in payload $triggersToStop = $triggersDeployed | Where-Object { $_.Name -in $triggerNamesInTemplate -and $_.RuntimeState -ne 'Stopped' } ` - | Where-Object { $triggerName = $_.Name; + | Where-Object { + $triggerName = $_.Name; $triggerInTemplate = $triggersInTemplate | Where-Object { $_.name.Substring(37, $_.name.Length - 40) -eq $triggerName }; Compare-TriggerPayload -triggerDeployed $_ -triggerInTemplate $triggerInTemplate -templateParameters $templateParameters } ` @@ -650,7 +652,12 @@ else { #Start active triggers - after cleanup efforts $triggersRunning = $triggersDeployed | Where-Object { $_.RuntimeState -eq 'Started' } | ForEach-Object { $_.Name } - $triggersToStart = $triggersInTemplate | Where-Object { $_.properties.runtimeState -eq "Started" -and $_.name.Substring(37, $_.name.Length - 40) -notin $triggersRunning } ` + $updatedTriggersInTemplate = $triggersInTemplate | ForEach-Object { + $jsonTrigger = ConvertTo-Json -InputObject $_ -Depth 10 -EscapeHandling Default + Update-TriggerTemplate -templateJson $jsonTrigger -templateParameters $templateParameters + } | ConvertFrom-Json -Depth 10 + + $triggersToStart = $updatedTriggersInTemplate | Where-Object { $_.properties.runtimeState -eq "Started" -and $_.name.Substring(37, $_.name.Length - 40) -notin $triggersRunning } ` | Where-Object { $_.properties.pipelines.Count -gt 0 -or $_.properties.pipeline.pipelineReference -ne $null } | ForEach-Object { New-Object PSObject -Property @{ Name = $_.name.Substring(37, $_.name.Length - 40)