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.