Skip to content
Latchkey

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 under pipelines.
  • Key it on a glob like v* or v*.*.*.
  • Read the tag from $BITBUCKET_TAG inside the step.
  • Push git tag v1.2.0 && git push origin v1.2.0 to 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_TAG is 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

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