Is there a way to trigger the creation of branches when a new repository is created in Azure Git?

70 Views Asked by At

Is there a way to trigger the creation of branches when a new repository is created in Azure Git?

I know we can automate the creation of an azure git repository and then create the branches via powershell. However, we have developers that will eventually create their own repositories and it would be nice if we could automatically see the new repository and then create a development, release and hotfix branch.

1

There are 1 best solutions below

0
Scott Richards On

I am not aware of any setting in Azure DevOps that would automatically create a set of default branches for repositories.

As a way to create this solution yourself, you can create some type of automation that triggers on a timer set to a frequency of your choice. You can store this logic in:

  • a yaml pipeline and configure that pipeline with a schedule to trigger with the frequency of your choice (keep in mind that if this is triggering very frequently that an agent will need to be available).
  • as a serverless function in your cloud provider (such as Azure Function App or Logic App), keeping in mind that this would incur additional charge.
  • a scheduled task on any machine.

The logic of the automation can use these two APIs:

You can call the list repositories API to return a list of repositories. You can then iterate through the list of repositories and call the list branches API for each. Check if your desired list of branches exist, and if not, create them using git.