Can needs keyword be made to require only one of tasks (i.e. needs [a or b])?

Can needs statement be made to require only one of tasks?

I read about needs statement here. Keyword reference for the `.gitlab-ci.yml` file | GitLab. I would like to have needs statement that needs either one or another but not necessarily both of them.

My .gitlab-ci.yml:

stages:
  - stage1
  - stage2
  - stage3

job1:
  stage: stage1
  script:
    - echo "job1"

job2a:
  stage: stage1
  when: manual
  script:
    - echo "job2a"

job2b:
  stage: stage1
  when: manual
  script:
    - echo "job2b"

job3:
  needs:
    - job: job2a
      optional: true
    - job: job2b
      optional: true
  stage: stage2
  script:
    - echo "Depending job"

job4:
  stage: stage3
  script:
    - echo "job4"

In this example I want that job3 would run if either job2a or job2b has run. My current code which I pasted above waits for both to complete (which is not guaranteed). I didnt notice from documentation how to do it.

1 Like