Home > OS >  How to use regex in gitlab-ci if rules?
How to use regex in gitlab-ci if rules?

Time:02-25

I would be very happy if someone could help me with the following issue. I would like to run specific scripts only for tags starting with a given tag name.

The following rule works well for the tag 'wind-index' but what I need is a regex as I would like it to work also for tags such as 'wind-index_0.1'

  rules:
    - if: $CI_COMMIT_TAG == "wind-index"
      when: always

I was expecting this to work but without success....

  rules:
    - if: $CI_COMMIT_TAG == \^wind-index\
      when: always

I've tried all possible combinations with simple quotes, double quotes or \^wind-index.*\, none are working.

Any suggestion, help is more than welcome :-)

CodePudding user response:

You need

  • / as regex delimiters
  • == is equality comparison operator, you need a regex matching operator, =~.

You can use

 rules:
    - if: $CI_COMMIT_TAG =~ /^wind-index/
      when: always

CodePudding user response:

That should do the trick:

- if: $CI_COMMIT_TAG =~ /^wind-index/
  • Related