I want to be able to trigger a deployment to a special server every time a tag matching a pattern is pushed.
I use the following job definition:
# ...
deploy to stage:
image: ruby:2.2
stage: deploy
environment:
name: foo-bar
script:
- apt-get update -yq
- apt-get install -y ruby-dev
- gem install dpl
# - ...
only:
- tags
Now my question: how can I limit this to tags that have a certain name, for example starting with "V", so that I can push a tag "V1.0.0" and have a certain job running?
Only
accepts regex patterns so for your use case it would be:
only:
- /^V.*$/
except:
- branches
- triggers
The best way to do is filtering by the Gitlab CI/CD variables matching your pattern
only
variables:
- $CI_COMMIT_TAG =~ /^my-custom-tag-prefix-.*/
As the documentation says:
CI_COMMIT_TAG
: The commit tag name. Present only when building tags.Since only / except are now being deprecated, you should now prefer the rules
keyword
Things get pretty simple, here's the equivalent using rules:
rules:
# Execute only when tagged starting with V followed by a digit
- if: $CI_COMMIT_TAG =~ /^V\d.*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With