Cancel Azure Data Factory Pipeline Runs via Synapse / Data Factory

Problem Statement 

One can cancel the current pipeline, which is in an execution state, via the Azure portal.

Login to Azure Portal → Go to ADF instance → Click on Manage → Monitor → Hover over the Pipeline execution state → Click on Cancel / Cancel Recursive

Pipeline runs

Is it possible to Cancel the pipeline run via Azure Data Factory / Synapse pipelines itself?

Prerequisites

  • Azure Data Factory /Synapse

Solution

Grant the Azure Data Factory / Synapse Data Factory Contributor access to the Data Factory whose pipeline execution needs to be canceled.

a) Login to Azure Portal - Go to ADF instance - Click on Access Control (IAM) - Add - Add role assignment

Access Control

b) Select the Data Factory Contributor role

Add role assignment

c) Select the necessary Azure Offering in members and Click on Review and assign

Review + Assign

2. Use ADF / Synapse Web Activity and ADF REST API for canceling the Pipeline run.

Pipeline Parameters

  • SubscriptionID
  • ResourceGroupName
  • DataFactoryName
  • PipelineRunID

Parameters

3. Web Activity Config

Web activity configuration

GitHUB Code

URL

@concat(
    'https://management.azure.com/subscriptions/',
    pipeline().parameters.SubscriptionID,
    '/resourceGroups/',
    pipeline().parameters.ResourceGroupName,
    '/providers/Microsoft.DataFactory/factories/',
    pipeline().parameters.DataFactoryName,
    '/pipelineruns/',
    pipeline().parameters.PipelineRunID,
    '/cancel?isRecursive=true&api-version=2018-06-01'
)
  • Method: POST
  • Authentication: System Assigned Managed Identity
  • Resource: https://management.azure.com


Similar Articles