How to condition a job on the previous success of one job OR another

Have been using needs: to check if one job AND another have succeeded, but would like to be able to need for one job OR another to be true. What’s the best way to do this otherwise? Have not had success with

if: |
  github.job.this_job == success()
  ||
  github.job.that_job == success()

either.

As mentioned in the document: Identifies any jobs that must complete successfully before this job will run. It can be a string or array of strings. If a job fails, all jobs that need it are skipped unless the jobs use a conditional statement that causes the job to continue.
So you can use needs and conditional in your yaml, such as:

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
    ......

  job2:
    runs-on: ubuntu-latest
    steps:
    ......
 
  job3:
    needs: [job1, job2]
    if: ${{ (needs.job1.result == 'success' || needs.job2.result == 'success') && always() }}
    runs-on: ubuntu-latest
    steps:
    ......

Note: Be sure to use always() in your if expression. If your if expression does not contain any of the status functions it will automatically result with success() as mentioned here.
More about needs context please refer here.

2 Likes