Azure Data Factory: How to stop/start triggers in ADF environments using CI/CD release pipeline?

Reyshma Sekar 20 Reputation points
2025-01-30T13:27:11.65+00:00

We would like to stop all triggers in our dev ADF environment after deploying to production. I've seen the below script being used:

  • task: AzurePowerShell@4 displayName: 'Data Factory: Stop all triggers'

inputs: azureSubscription: '${{ parameters.connection }}'

ScriptType: InlineScript

Inline: | $triggers = Get-AzDataFactoryV2Trigger -ResourceGroupName ${{ parameters.resourcegroupName }} -DataFactoryName ${{ parameters.dataFactoryName }} -ErrorAction SilentlyContinue

if($triggers)

{ for each($trigger in $triggers)

{ Stop-AzDataFactoryV2Trigger -ResourceGroupName ${{ parameters.resourcegroupName }} -DataFactoryName ${{ parameters.dataFactoryName }} -Name $trigger. TriggerName -Force } }

azurePowerShellVersion: latest version

When I break it down and run Get-AzDataFactoryV2Trigger, it returns all the triggers in my data factory but when running Stop-AzDataFactoryV2Trigger, it returns true but when checking in ADF, the trigger is not stopped. I tried to run these commands in the release pipeline using Azure Powershell and, in the portal, using Azure CLI. confirmed the right subscription is being used.

Confirmed that the DataFactory Contributor role is set for the dev resource group and other permissions are set up for the subscription and resource group.

What else can I try? Has anyone had this issue before?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

Accepted answer
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2025-01-31T12:54:53.8933333+00:00

    Hello Reyshma Sekar,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to stop/start triggers in ADF environments using CI/CD release pipeline in Azure Data Factory.

    Instead of generic troubleshooting for common issues, since Stop-AzDataFactoryV2Trigger returns True but does not actually stop the triggers, the root cause was limited to these four areas:

    1. Triggers Are in a Queued or Inactive State
    2. Some triggers are linked to pipelines that need explicit stopping.
    3. If using an older version, this could be a known issue.
    4. If an ARM policy enforces a specific trigger state, it may automatically restart or prevent the stop command from taking effect.

    Therefore, my best practice advice to resolve your issue are the followings:

    1. Use the Azure REST API to Stop Triggers:
            $accessToken = (Get-AzAccessToken -ResourceUrl "https://management.azure.com").Token
            $resourceGroupName = "<Your_ResourceGroup>"
            $dataFactoryName = "<Your_DataFactory>"
            $triggers = Get-AzDataFactoryV2Trigger -ResourceGroupName $resourceGroupName -DataFactoryName $dataFactoryName
            foreach ($trigger in $triggers) {
                $triggerName = $trigger.TriggerName
                $url = "https://management.azure.com/subscriptions/<your_subscription_id>/resourceGroups/$resourceGroupName/providers/Microsoft.DataFactory/factories/$dataFactoryName/triggers/$triggerName/stop?api-version=2018-06-01"
                Invoke-RestMethod -Uri $url -Method Post -Headers @{Authorization="Bearer $accessToken"} -ContentType "application/json"
                Write-Output "Stopping trigger: $triggerName"
            }
      
    2. Verify Trigger State:
         Get-AzDataFactoryV2Trigger -ResourceGroupName $resourceGroupName -DataFactoryName $dataFactoryName | ForEach-Object {
           $_.Properties.RuntimeState
            }
      
    3. Check for Auto-Restart Policies:
      1. In the Azure Portal, check the trigger settings for any auto-restart policies.
      2. Ensure that triggers are not linked to pipelines with Start on Completion dependencies.
    4. Update Azure PowerShell Module:
            Update-Module -Name Az -Force
            (Get-Module -Name Az).Version
      

    This will resolve the issue.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.