How to dynamically pass variable based on the branch the ADF pipeline is triggering from

Daniel Yang 0 Reputation points
2025-02-08T00:27:56.4233333+00:00

I am looking for a way to dynamically pass a variable based on what git branch the pipeline is running on. Alternatively, if within ADF I can extract the contents of the linked service JSON that should be sufficient for my task. Is there a way to specify a parameter/variable that can be git ignored for each branch? These branches will be merged together from time to time so I can't just specify each branch to use different variables.

For context: these branches are supposed to represent dev, uat, and prod. I have an azure function that, depending on which branch the pipeline is being triggered, will pull from blobs that correspond to each environment. I understand "best practices" would have been to have different factories altogether for each environment, however that is not an option for me.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,350 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VINODH KUMAR 30,031 Reputation points MVP
    2025-02-10T01:21:06.08+00:00

    Hi ,

    Thanks for reaching out to Microsoft Q&A.

    1. Use Global Parameters and Trigger Overrides

    Global parameters are available across all pipelines and can be used to define environment-specific configurations. You can override the values dynamically based on the trigger used to run the pipeline.

    Steps:

    1. Create Global Parameters:
      • In ADF, go to "Manage" > "Global Parameters."
      • Define a global parameter for the env, example: Environment.
    2. Override Global Parameter Values in Triggers:
      • Create separate triggers for each environment (example: Trigger_Dev, Trigger_UAT, Trigger_Prod).
      • Override the global parameter Environment in each trigger with the branch/environment name.
    3. Use the Global Parameter in Pipelines:
      • In your pipeline, reference the global parameter using @pipeline().globalParameters.Environment.
    4. Dynamic Behavior:
      • Pass the global parameter's value to your azfunc or any downstream linked service dynamically based on the trigger.

    1. Extract the Branch Name Dynamically

    Unfortunately, ADF does not natively support detecting the Git branch during runtime. However, you can:

    1. Set an environment-specific variable in the trigger metadata or pipeline parameter, and pass it dynamically during pipeline execution.

    Steps:

    Parameterize Pipeline:

    • Add a pipeline parameter named BranchName.

    Set Parameter Value in Triggers:

      - In each branch's trigger, pass the respective branch name as the parameter value (e.g., `dev`, `uat`, `prod`).
      
    
    1. Use the Parameter in Pipelines:
      • Use @pipeline().parameters.BranchName wherever needed in activities or linked services.

    3.Externalize Configuration in a Blob or Key Vault

    Store the environment-specific configurations in a central location (ex: Azure Blob Storage or Key Vault) and dynamically fetch the configurations based on the branch.


    1. Dynamically Access Linked Service JSON Content

    ADF does not support direct runtime access to the linked service JSON file. However, you can parameterize your linked services and dynamically pass environment-specific values.


    1. Use GitIgnored Files for Environment-Specific Parameters

    You can maintain a settings.json file in your repository for each branch and include it in .gitignore to avoid conflicts during merges. Each branch can have its unique settings.json file with environment-specific configurations.

    Please feel free to click the 'Upvote' (Thumbs-up) button and 'Accept as Answer'. This helps the community by allowing others with similar queries to easily find the solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.