Stop and Start ADF triggers with Azure DevOps Deployment Pipeline
Running a deployment on Azure DevOps for Azure Data Factory requires triggers to be stopped just to make sure that no trigger gets fired during the deployment process. Usually Microsoft recommends a big pre and post script that you can use to achieve the same and more. But if your focus is to just deal with Triggers we have a nice powershell way to do it.
The release pipeline will look something like this
Now we have to create a script to achieve the same.
param (
[Parameter (Mandatory = $true)][string]$ResourceGroupName,
[Parameter (Mandatory = $true)][string]$DataFactoryName,
[Parameter (Mandatory = $false)][Bool] $triggerOFF
)
#Triggers
$triggersADF = Get-AzureRmDataFactoryV2Trigger -DataFactoryName $DataFactoryName -ResourceGroupName $ResourceGroupName
if ($triggerOFF -eq $true) {
#Turn Off all the triggers
$triggersADF | ForEach-Object {
Write-host "Disabling trigger " $_.name
Write-host " runtimeState:" $_.properties.runtimeState
Stop-AzureRmDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -TriggerName $_.name -Force
}
}
else {
#Turn On the triggers
$triggersADF | ForEach-Object {
Write-host "Enabling trigger " $_.name
Write-host " runtimeState:" $_.properties.runtimeState
Start-AzureRmDataFactoryV2Trigger -ResourceGroupName $ResourceGroupName -DataFactoryName $DataFactoryName -TriggerName $_.name -Force -ErrorAction SilentlyContinue
}
}
We can use the same to start and stop all the triggers based on the requirements.
Change the Script Arguments from $true to $false to Switch on all the triggers.
Note: make sure no triggers must be associated with one or multiple pipelines.