Skip to content
Latchkey

How to Deploy on a Tag in Azure Pipelines

Azure Pipelines fires on tags via trigger.tags, and you gate the deploy stage on the tag ref.

Add tags: under trigger: to run on tag pushes, then gate the deploy stage with a condition that checks Build.SourceBranch starts with refs/tags/.

Trigger on tags, deploy on tag refs

The pipeline triggers on v* tags; the deploy stage runs only for tag builds.

azure-pipelines.yml
trigger:
  tags:
    include:
      - 'v*'

stages:
  - stage: deploy
    condition: startsWith(variables['Build.SourceBranch'], 'refs/tags/')
    jobs:
      - job: deploy
        steps:
          - script: ./deploy.sh "$(Build.SourceBranchName)"

Gotchas

  • On a tag build, Build.SourceBranch is refs/tags/v1.2.3 and Build.SourceBranchName is just v1.2.3.
  • If you set both branches: and tags: under trigger:, list them explicitly - adding tags: alone does not disable branch CI.
  • A custom stage condition: replaces the default succeeded(); include it if upstream stages must pass.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →