How to Deploy on a Tag With the tags Pipeline in Bitbucket Pipelines
Define a tags: section with a glob such as v* so a deploy pipeline runs only when a matching tag is pushed.
The tags (or tag) pipeline section matches Git tag pushes by glob. Use it to keep day-to-day commits off the release path and only deploy when you cut a version tag.
Steps
- Add a
tags:block underpipelines. - Key it on a glob like
v*orv*.*.*. - Read the tag from
$BITBUCKET_TAGinside the step. - Push
git tag v1.2.0 && git push origin v1.2.0to trigger it.
Pipeline
bitbucket-pipelines.yml
pipelines:
tags:
'v*':
- step:
name: Release deploy
deployment: production
script:
- echo "Releasing $BITBUCKET_TAG"
- ./build.sh
- ./deploy.sh --version "$BITBUCKET_TAG"Gotchas
- Tag globs use fnmatch wildcards, not full regex.
$BITBUCKET_TAGis only set in tag pipelines; it is empty on branch builds.- A push that creates both a branch and a tag triggers both matching pipelines.
Related guides
How to Deploy on the main Branch Only in Bitbucket PipelinesRestrict deploys to the main branch in Bitbucket Pipelines by placing the deploy step under branches: main, s…
How to Do a Blue-Green Deploy With Bitbucket PipelinesRun a blue-green deploy from Bitbucket Pipelines by releasing to the idle color, health-checking it, then swi…