How to exclude azure-pipelines.yml file in fix branch

Viewed 655

We are setting up Azure Pipelines in one of our projects. Hence, we added azure-pipelines.yml to development branch. However, when devs create a fix branch off development branch, that branch also contains azure-pipelines.yml. So, when devs commit to that fix branch, it is triggering a pipeline release.

How can we prevent that from happening?

1 Answers

Once a file is added to Git, you cannot just "untrack" it. Even adding it to the .gitignore won't help.

Fortunately, Azure Pipelines' developers (as all other CI/CD services developers) understand this too and all CI/CDs provide an option to be triggered only on specific branches (or only on tags). In Azure Pipelines, you can control which branches get triggered with a trigger config, which accepts a list of refs:

trigger:
  branches:
    include:
      - master
      - releases/*
    exclude:
      - fix/*

You can also apply conditions to particular jobs:

- job: B
  condition: eq(variables['build.sourceBranch'], 'refs/heads/master')
  steps:
    - script: echo this only runs for master
Related