Reputation: 399
I am tyring to set rule for deployment stage in gitlab-ci.yml file where if the git commit message is having a particular [STRING] in this format then it should deploy to that particular environment where this rule is written.
# Deploy to QAT environment
deploy-qat:
stage: deploy
extends: .helm_deploy
environment:
name: qat
tags:
- exe-prd
rules:
- if: $CI_COMMIT_MESSAGE =~ "/[QAT]$/|/[qat]$/" #&& $CI_COMMIT_REF_NAME == "example/qat"
when: always
I have wrote above rule however it is not working. I have tried below combinations of regular expressions however none of them are working.
"/\[QAT\]/|/\[qat\]/"
"/[QAT]/|/[qat]/"
"*\[QAT\]*|*\[qat\]*"
"\[\(QAT\|qat\)\]"
"\[\(QAT\|qat\)]"
"/\[(qat|QAT)\]/"
I tried following website for regular expression here which validates my requirement but it is not working inside gitlab-ci.yml file.
Upvotes: 11
Views: 52679
Reputation: 626738
You can use
# Deploy to QAT environment
deploy-qat:
stage: deploy
extends: .helm_deploy
environment:
name: qat
tags:
- exe-prd
rules:
- if: $CI_COMMIT_MESSAGE =~ /\[(QAT|qat)]/
when: always
See more about how to format regex matching conditions at the rules:variables
reference page.
NOTES:
/\[(QAT|qat)]/
should not be put inside quotes/.../
regex literal syntax (the backslashes are regex delimiters)\[(QAT|qat)]
is a regex that matches [
, then either QAT
or qat
, and then a ]
char=~
is a regex matching operator.Upvotes: 24
Reputation: 39
Try this block in your yml:
deploy-qat:
only:
message:
- /\[(qat|QAT)\]/
Upvotes: 0