How to trigger a pipeline when new branch is created

Viewed 917

My requirement is I have to create a branch policy when ever a new branch is created through automation. I have the Az cli script and Azure devops pipeline to apply for the new branch which.

How to dynamically take the new branch name and automatically has to trigger the pipeline to apply the policy on the branch? Please suggest me. I am using Azure devops, Azure repo.

1 Answers

How to dynamically take the new branch name and automatically has to trigger the pipeline to apply the policy on the branch?

If you are using yaml pipeline, you can set trigger to the new branch name in the azure-pipelines.yml file, so that the pipeline will be triggered automatically when the branch is created.

trigger:
- dev 

Then in the pipeline, you can through Build.SourceBranchName predefined variable to get branch name.

Build.SourceBranchName: The name of the branch in the triggering repo the build was queued for.

Related