Update pipeline status variable to fail if any activity fails, otherwise succeed

Aditya Singh 105 Reputation points
2024-04-09T16:02:52.0466667+00:00

I have a pipeline that consists of multiple activities, and I want to update the value of a variable called STATUS to Fail if any activity fails. Otherwise, I want it to be set to Success using the Pipeline expression builder. How can I accomplish this?

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,749 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,487 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,467 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,736 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Nandan Hegde 29,901 Reputation points MVP
    2024-04-10T04:24:32.9166667+00:00

    Hey,

    The below blog provides a framework to get the details:

    https://datasharkx.wordpress.com/2021/08/19/error-logging-and-the-art-of-avoiding-redundant-activities-in-azure-data-factory/

    based on dependencies and checking the expression whether the final concatination of the error messages are empty or has some value.
    And based on that you can have the status as fail or success

    0 comments No comments

  2. Pinaki Ghatak 2,400 Reputation points Microsoft Employee
    2024-05-13T09:08:44.2666667+00:00

    Hello @Aditya Singh

    You can achieve this by using the If Condition activity and Set Variable activity in your pipeline. Here are the steps:

    1. Add an If Condition activity to your pipeline and set its expression to check if the activity has failed. You can use the dynamic expression @activity('activityName').output.status to check the status of the activity. If the activity has failed, the expression will return 'Failed', otherwise it will return 'Succeeded'.
    2. Inside the If Condition activity, add a Set Variable activity to set the value of the STATUS variable. If the activity has failed, set the value of the variable to 'Fail', otherwise set it to 'Success'. You can use the dynamic expression if(equals(activity('activityName').output.status, 'Failed'), 'Fail', 'Success') to set the value of the variable. Here is an example of what your pipeline might look like:
    {
        "name": "examplePipeline",
        "properties": {
            "activities": [
                {
                    "name": "exampleActivity",
                    "type": "Copy",
                    "inputs": [
                        {
                            "referenceName": "exampleInputDataset",
                            "type": "DatasetReference"
                        }
                    ],
                    "outputs": [
                        {
                            "referenceName": "exampleOutputDataset",
                            "type": "DatasetReference"
                        }
                    ],
                    "typeProperties": {
                        "source": {
                            "type": "BlobSource"
                        },
                        "sink": {
                            "type": "BlobSink"
                        }
                    }
                },
                {
                    "name": "setStatusVariable",
                    "type": "SetVariable",
                    "dependsOn": [
                        {
                            "activity": "exampleActivity",
                            "dependencyConditions": [
                                "Succeeded",
                                "Failed"
                            ]
                        }
                    ],
                    "typeProperties": {
                        "variableName": "STATUS",
                        "value": {
                            "value": "@if(equals(activity('exampleActivity').output.status, 'Failed'), 'Fail', 'Success')",
                            "type": "Expression"
                        }
                    }
                }
            ],
            "variables": {
                "STATUS": {
                    "type": "String",
                    "defaultValue": "Success"
                }
            },
            "annotations": []
        }
    }
    
    1. In this example, the pipeline has two activities: the exampleActivity and the setStatusVariable activity. The setStatusVariable activity depends on the exampleActivity

    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    0 comments No comments