I want to create some nested conditions: i need this pipeline to work when it is a merge or merge request and with certain name start "feature". So, is there an AND condition in the 'only' option for jobs?
Is there an AND option on the rules condition in .gitlab-ci.yml?
Asked Answered
No there is not. You must use rules.
test:
stage: test
script:
- echo "test"
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TITLE =~ /^feature/'
Is multiline possible so the && chain stays readable? –
Jameljamerson
@Jameljamerson as far as I know that's unfortunately not possible. Multiline commands can only be used in
script
, before_script
and after_script
–
Bledsoe @Jameljamerson - whiel you can't have them "chained" with the - > or - | (multiline) you can use brackets such as
( condition1 && condition2 && condition3 )
and put each condition in new line. Keep in mind that each line has to be indented correctly, which you can verify using the pipeline editor. See such example here. –
Hagiographer Updated relevant doc link: docs.gitlab.com/ee/ci/jobs/… –
Kaduna
There's another operator that the AND operator.
You can replace the AND
in your the gitlab-ci.yml file with the &&
operator. That's how we make it !
© 2022 - 2025 — McMap. All rights reserved.
if
statements. Combined withwhen
, right? – Mallen