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.SourceBranchisrefs/tags/v1.2.3andBuild.SourceBranchNameis justv1.2.3. - If you set both
branches:andtags:undertrigger:, list them explicitly - addingtags:alone does not disable branch CI. - A custom stage
condition:replaces the defaultsucceeded(); include it if upstream stages must pass.
Related guides
How to Deploy on a Tag or Release in GitHub ActionsTrigger a GitHub Actions deploy only on a version tag or published release with on.push.tags and the release…
How to Build and Push a Docker Image in Azure PipelinesBuild and push a Docker image in Azure Pipelines with the Docker@2 task and a container registry service conn…