starting point
I use semantic-release for automated releasing. When a release is created I have a commit message like
chore(release): \d+.\d+.\d+
and a tag d\+.\d+.\d+
created.
I have following gitlab-ci.yml
for testing
---
stages:
- debug
- test
- release
- deploy
debugging:
stage: debug
variables:
GIT_STRATEGY: clone
script:
- echo "GitLab CI/CD | Print all environment variables"
- env | sort
test1:
stage: test
variables:
GIT_STRATEGY: clone
script:
- echo "run tests"
semantic-release:
stage: release
variables:
GIT_STRATEGY: clone
script:
- echo "run semantic release"
deploy-pages:
stage: deploy
variables:
GIT_STRATEGY: clone
script:
- echo "deploy pages"
I want to achieve the following:
- run the
deploy-pages
job only once for an automated release commit - run the
test1
andsemantic-release
jobs only for non automated release commits, i.e. regular commits created by actual humans.
What is the best way to do that?
My current status
I for my automatic releases two pipelines are triggered, one tag pipeline and one regular commit pipeline.
I already achieved 1. by adding
rules:
- if: $CI_COMMIT_TAG != null
- when: never
to the job deploy-pages
.
Solving 2. is where my problem actually is.
In my latest attempts I try to use regex matching against $CI_COMMIT_MESSAGE
, i.e. a rules
block for test1
and sematic-release
jobs like
rules:
- if: $CI_COMMIT_MESSAGE =~ $RELEASE_COMMIT_MSG_PATTERN
when: never
- if: $CI_COMMIT_TAG != null
when: never
- when: on_success
where I tried following $RELEASE_COMMIT_MSG_PATTERN
s in a global variables:
block
RELEASE_COMMIT_MSG_PATTERN: "/^chore(release): [[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+$/"
RELEASE_COMMIT_MSG_PATTERN: "/^chore(release): \\d+\\.\\d+\\.\\d+$/"
RELEASE_COMMIT_MSG_PATTERN: "/^chore(release): .*"
RELEASE_COMMIT_MSG_PATTERN: "/^chore(release):/"
But the regex match seems not to work.
In addition to my question above: Is there a way to test the regex match?
I am thinking of a tool like https://regex101.com/ but for gitlab regex (based on Re2 which according to Choose when to run jobs | GitLab is what is used in Gitlab).