Skip to content
Latchkey

How to Deploy on a Git Tag With Azure Pipelines

A trigger that includes refs/tags/v* fires the pipeline only when a matching version tag is pushed.

Set the trigger to match refs/tags/v* and exclude branches so the deploy runs only for tag pushes. Read the tag from Build.SourceBranchName.

Steps

  • Set trigger.tags.include to your version glob (for example v*).
  • Exclude branches if you want tag-only runs.
  • Read the tag name from $(Build.SourceBranchName).
  • Deploy using that version as the release identifier.

azure-pipelines.yml

azure-pipelines.yml
trigger:
  branches:
    exclude: ['*']
  tags:
    include:
      - 'v*'
pool:
  vmImage: ubuntu-latest
steps:
  - script: echo "Releasing $(Build.SourceBranchName)"
  - task: AzureWebApp@1
    inputs:
      azureSubscription: 'my-azure-rm'
      appName: 'my-web-app'
      package: '$(Build.ArtifactStagingDirectory)/app.zip'

Gotchas

  • For a tag build, Build.SourceBranch is refs/tags/v1.2.3; SourceBranchName is just v1.2.3.
  • Annotated and lightweight tags both trigger; the glob applies to the tag name only.

Related guides

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