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.includeto your version glob (for examplev*). - 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.SourceBranchisrefs/tags/v1.2.3;SourceBranchNameis justv1.2.3. - Annotated and lightweight tags both trigger; the glob applies to the tag name only.
Related guides
How to Deploy a Static Site to Azure Storage and CDN With Azure PipelinesUpload a built static site to an Azure Storage static website and purge the CDN endpoint from Azure Pipelines…
How to Run a Scheduled Nightly Deploy in Azure PipelinesDeploy on a schedule in Azure Pipelines with a YAML cron trigger, so a nightly build promotes to a staging en…