How to fail Azure Data Factory pipeline based on IF Task

Viewed 4811

I have a pipeline built on Azure data Factory. It has:

  1. a "LookUp" task that has an SQL query that returns a column [CountRecs]. This columns holds a value 0 or more.

  2. an "if" task to check this returned value. I want to fail the pipeline when the value of [CountRecs]>0

Is this possible?

2 Answers

You could probably achieve this by having a Web Activity when your IF Condition is true ([CountRecs]>0) in which the web activity should call the below REST API to cancel the pipeline run by using the pipelinerunID (you can get this value by using dynamic expression - @pipeline().RunId)

Sample Dynamic Expression for Condition: @greater(activity('LookupTableRecordCount').output.firstRow.COUNTRECS, 0)

REST API to Cancel the Pipeline Run: POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/cancel?api-version=2018-06-01

MS Doc related to Rest API: ADF Pipeline Runs - Cancel

One other possible way is to have an invalid URL in your web activity which will fail the Web activity in-turn it will fail the IfCondition activity, which inturn will result in your pipeline to fail.

There is an existing feature request related to the same requirement in ADF user voice forum suggested by other ADF users. I would recommend you please up-vote and/or comment on this feedback which will help to increase the priority of the feature request implementation.

ADF User voice feedback related to this requirement: https://feedback.azure.com/forums/270578-data-factory/suggestions/38143873-a-new-activity-for-cancelling-the-pipeline-executi

Hope this helps.

As a sort-of hack-solution you can create a "Set variable" activity which incurs division by zero if a certain condition is met. I don't like it but it works.

@string( 
  div(
    1 
  , if(
      greater( int(variables('date_diff')), 100 )
     , 0
     , 1
    )
  ) 
)
Related