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_TAGset and$CI_COMMIT_BRANCHempty - rule on the tag, not the branch. - The legacy
only: tagsworks butrules: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
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 GitLab CIBuild and push a Docker image in GitLab CI with docker:dind or Kaniko, logging in to the built-in container r…