GitLab CI/CD .gitlab-ci.yml 文件中的字符串比较不区分大小写

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

我有一些名称为 'MyVariable' 的变量,想将它与规则内部的一些字符串常量进行比较:if section inside job:

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

但 MyVariable 实际上可以在不同的情况下使用,例如:

SOME STRING
Some String
SoME strinG

等等。 当前比较 (==) 区分大小写,当 MyVariable 不完全是 'some string'(小写)时,表达式结果为 'false'。有没有可能以不区分大小写的方式比较两个字符串?

使用 =~ 而不是 == 可以让您使用 regular expression。您可以使用不区分大小写的表达式或添加不区分大小写的标志 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'

其他参考资料:

Regex: ignore case sensitivity