Skip to content

Support logical OR condition with needs keyword

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

I am trying to create a job dependency with "OR" condition for previous stage jobs using "needs" in ".gitlab.ci.yml" file but unable to find a solution for this.

stages:
  - build
  - test
  - deploy


Build_job:      
  stage: build
  script:
    - echo "hello from build job"

Test_job1:
  stage: test
  script:
    - echo "Start test 1"
  when: manual

Test_job2:
  stage: test
  script:
    - echo "Start test 2"
  when: manual

Deploy_job:
  stage: deploy
  script:
    - echo "Start deploying the job"
  when: manual
    needs:
      - job: Test_job1
        optional: true
      - job: Test_job2
        optional: true

My aim is either of Test_job1 or Test_job2 is passed Deploy_job should be enabled. But with the above code, I am unable to do so as Deploy_job is getting enabled only when both previous two test jobs are passed. Is there a way if something can be used like needs: [Test_job1 or Test_job2]?

Edited by 🤖 GitLab Bot 🤖