Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading