How to properly define regex as global variables in gitlab-ci.yml

I’m trying to define a regex expression as a global variable in gitlab-ci.yml.

the variable is:

variables:
  -SPEEDY_REGEX: '(chore|docs|feat|fix|refactor|style|test)\:( |\t)+\[SPEEDY\].*'

now I want to use it in if statements for getting specific builds to run:

build:
  rules:
    - if : '$CI_COMMIT_MESSAGE =~ $SPEEDY_REGEX'
      when: never
    - when: on_success
build:speedy:
  rules:
    - if : '$CI_COMMIT_MESSAGE =~ $SPEEDY_REGEX'
      when: on_success
    - when: never

This didn’t want to work for a reason I ignore.

1 Like

I think this is just a syntax thing, can you try:

# Note there's no "-" before the variable name
variables:
  SPEEDY_REGEX: "(chore|docs|feat|fix|refactor|style|test)\:( |\t)+\[SPEEDY\].*"

...build:
  rules:
    - if : '$CI_COMMIT_MESSAGE =~ $SPEEDY_REGEX'
      when: never
    - when: on_success
build:speedy:
  rules:
    - if : '$CI_COMMIT_MESSAGE =~ $SPEEDY_REGEX'
      when: on_success
   - when: never

and see what happens?