Case insensitive comparison of strings in .gitlab-ci.yml file of GitLab CI/CD

Viewed 1612

I have some variable with name 'MyVariable' and want to compare it with some string constant inside rules: if section inside job:

rules:
        - if: $MyVariable == 'some string'

But MyVariable actually can be in different cases, like:

SOME STRING
Some String
SoME strinG

and so on. Current comparison (==) is case-sensitive, and expression results to 'false' when MyVariable is not exactly 'some string' (in lower case). Is there any possibility compare two strings in case-insensitive way?

1 Answers

Using =~ instead of == lets you use a regular expression. You can use case-insensitive expression or add the case-insensitive flag i:

Regular expression flags must be appended after the closing /. Pattern matching is case-sensitive by default. Use the i flag modifier, like /pattern/i to make a pattern case-insensitive:

- if: '$MyVariable =~ /some string/i'

Additional references:

Regex: ignore case sensitivity

Related