This job runs anyway in a MR, is this a bug?
I tried different combinations as seen from the GitLab docs, but it continues to run or fails due to wrong syntax
somejob:
stage: somestage
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_MERGE_REQUEST_LABELS =~ /somelabel/
when: never
script:
- echo $CI_MERGE_REQUEST_LABELS
the job runs anyway and I can see that the label is there
$ echo $CI_MERGE_REQUEST_LABELS
somelabel
This is because your first rule will always catch first. Rules stop evaluation on the first match. Because $CI_MERGE_REQUEST_ID
will always be present on an MR, that first rule will always match before your $CI_MERGE_REQUEST_LABELS
rule.
Change the order to get the intended effect:
rules:
- if: $CI_MERGE_REQUEST_LABELS =~ /somelabel/
when: never
- if: $CI_MERGE_REQUEST_ID