Is there an AND option on the rules condition in .gitlab-ci.yml?
Asked Answered
A

2

33

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?

Atonsah answered 22/4, 2021 at 19:4 Comment(0)
B
47

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/'
Bledsoe answered 23/4, 2021 at 4:56 Comment(5)
While you can have multiple if statements. Combined with when, right?Mallen
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_scriptBledsoe
@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
F
1

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 !

Fillip answered 8/5, 2023 at 8:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.