Skip to content
Latchkey

How to Deploy on a Tag in GitLab CI

Gate a GitLab deploy job on $CI_COMMIT_TAG so it runs only for tag pipelines.

Use a rules: entry checking $CI_COMMIT_TAG. The tag name is in $CI_COMMIT_TAG; combine with a pattern to require a v* tag.

Run only on version tags

The job is added to the pipeline only when a tag matching v* triggered it.

.gitlab-ci.yml
deploy:
  stage: deploy
  script:
    - ./deploy.sh "$CI_COMMIT_TAG"
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\\d+\\.\\d+\\.\\d+$/'

Gotchas

  • Tag pipelines have $CI_COMMIT_TAG set and $CI_COMMIT_BRANCH empty - rule on the tag, not the branch.
  • The legacy only: tags works but rules: is preferred and lets you match a version pattern.
  • Create a release with the release: keyword (release-cli) in the same tagged pipeline if you want a GitLab Release object.

Related guides

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