Add option for job `requires` to be or-ed instead of and-ed

I have a case where I want multiple a job to depend on only 1 of multiple jobs

workflows:
  version: 2
  build-test-and-generate-binary:
    jobs:
      - job1
      - job2
      - job3:
          type: approval
          requires: # Want to have the option here so that if *either* job1 *or* job2 ends, job3 will start.
            - job1
            - job2
      - job4:
          requires:
            - job3
2 Likes

@yousefhamza Did you ever come up with a solution for this?

No I didn’t :confused:

1 Like

:wave: Hi @yousefhamza,

Maybe you could use the same logic as this workaround :thinking:

In your case though, the loop in the waiter job would be slightly different:

      - run: |
          until [[ $(curl --location --request GET "https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job" --header "Circle-Token: $CCI_TOKEN"| jq -r '.items[]|select(.name == "job1" or .name == "job2")|.status' | grep -c "success") -gt 0 ]]; do
            sleep 1
          done

And then your workflow would be:

workflows:
  version: 2
  build-test-and-generate-binary:
    jobs:
      - job1
      - job2
      - waiter
      - job3:
          type: approval
          requires:
            - waiter
      - job4:
          requires:
            - job3

With the above configuration, job3 will start as soon as either job1 or job2 finishes successfully.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.