Skip to content

Gitlab ci validation complains about using rules with && and || at the same time

Gitlab ci validator complains that the following syntax is incorrect:

rules: # Only if it matches the tag of vx.x.x or vx.x and it is either to master or production
      - if: '($CI_MERGE_REQUEST_TARGET_BRANCH == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH == "production") && $CI_COMMIT_TAG =~ /^v[0-9](?:\.[0-9]){2,3}/'
        when: always

After I removed the () the syntax looks valid, but the rule is not what I wanted anymore. How can I change the order of boolean conditions in the rules?

I thought the following should work, but it didn't.

rules: 
      - if: '$CI_MERGE_REQUEST_TARGET_BRANCH == "master" && $CI_COMMIT_TAG =~ /^v[0-9](?:\.[0-9]){2,3}/'
            when: always
      - if: '$CI_MERGE_REQUEST_TARGET_BRANCH == "production" && $CI_COMMIT_TAG =~ /^v[0-9](?:\.[0-9]){2,3}/'
            when: always
Edited by Jason Yavorsky