Reputation: 511
I'm using GitLab.com. I want to run a job when it's on the beta branch and the commit message doesn't start with: chore(release)
. Here is my attempt:
# --snip--
release_beta:
stage: 📦 release
image:
name: <private_image>
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
before_script:
- cp $SR_CONFIG_PATH/.releaserc.json .
script:
- npx semantic-release
rules:
# so we don't trigger a release job when semantic-release pushes the release
- if: '$CI_COMMIT_BRANCH == "beta" && $CI_COMMIT_MESSAGE !~ /^chore(release)/'
This doesn't work and the job is always triggered on the beta
branch. I tried with =~
variation and it didn't work either. I can't seem to make the regex test work even though it's mentioned in the documentation: https://docs.gitlab.com/ee/ci/jobs/job_control.html#common-if-clauses-for-rules.
The job failed because the user doesn't have the permissions for that image (that's the reason I want to prevent the job from running in the first place):
Upvotes: 0
Views: 1207
Reputation: 530920
Parentheses define capturing groups. You have to escape them to match literal parentheses.
- if: '$CI_COMMIT_BRANCH == "beta" && $CI_COMMIT_MESSAGE !~ /^chore\(release\)/'
Upvotes: 1