In gitlab pipeline I have a job with rule using "reference". How do I add another condition in the same rule using
.rules:default:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
- if: $CI_COMMIT_REF_NAME == "main" && $VERSION_NUMBER != "current"
myjob:
stage: myjob
script:
- echo "I am executing myjob"
rules:
- $Environment == "sbx" && !reference [".rules:default", rules]
this show this as error This GitLab CI configuration is invalid: jobs:myjob rules should be an array containing hashes and arrays of hashes
You can't do string interpolations with !reference
-- there are no interpolation primitives in the YAML spec, either.
However, you can get a the same effect you want by using an additional rule instead:
rules:
- if: $Environment != "sbx"
when: never
- !reference [".rules:default", rules]