I have a requirement wherein a ForEach activity must break when an inner activity fails. How do i implement that.

Yasmeen Mohmmad 21 Reputation points

I have created an adfv2 pipeline, lookup-->ForEach. I have implemented few activities inside the ForEach activity.
I want the ForEach activity to break( stop iterating) if any inner activity fails. How do i implement that.
Can someone please help me on this.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
6,270 questions
No comments
{count} votes

Accepted answer
  1. KranthiPakala-MSFT 32,976 Reputation points Microsoft Employee

    Hi @Yasmeen Mohmmad ,

    Welcome to Microsoft Q&A forum and thanks for reaching out.

    Unfortunately there is no out of box feature to break the ForEach activity iteration if any of the inner activities fails.

    Here is an existing feature request submitted by another user in ADF user voice forum. Please feel free to up-vote and/comment on it to help increase the priority of the feature implementation. - https://feedback.azure.com/forums/270578-data-factory/suggestions/39673909-foreach-activity-allow-break

    But here is a workaround which you could implement to can cancel the pipeline run when an inner activity of ForEach is failed.

    For each activity inside ForEach declare a Success (green) and Failed(red) dependency, and when that particular activity fails then it enters Failed path where you use a Web activity in which you can call Pipeline Runs - Cancel API to cancel the current pipeline run by passing the current pipeline run ID. You can get the current pipeline run ID using this expression - @pipeline().RunId


    To cancel a pipeline run by its run ID, use this :

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

    runID = @pipeline().RunId

    Hope this helps.


    Please don’t forget to Accept Answer and Up-Vote wherever the information provided helps you, this can be beneficial to other community members.

0 additional answers

Sort by: Most helpful