Reputation: 658
I'm trying to achieve a flow with a job dependency tree based on needs
and if
This is the workflow file, and my problem is that the job4 is not being triggered even when the job3 is being executed successfully.
I can't find any documentation explaining what is happening, but it seems that the needs
tree that is being built behind the scenes is not matching the job4, because the needs
on the job3 is not completed (is forced by the if
)
I have a workaround to solve this flow using job outputs, but I was wondering why the simple example is not working. Can anyone explain me why?
Thanks
name: Test Workflow
on:
push:
jobs:
job1:
runs-on: ubuntu-latest
steps:
- run: echo Job1
job2:
if: cancelled()
runs-on: ubuntu-latest
steps:
- run: echo Job2
job3:
if: always()
needs: [job1, job2]
runs-on: ubuntu-latest
steps:
- run: echo Job3
job4:
needs: job3
runs-on: ubuntu-latest
steps:
- run: echo Job4
Upvotes: 0
Views: 271
Reputation: 40869
All dependent jobs must succeed. So jon your job 4 depdends on the job 3 it must that job 3 and all it's need must be succeded.
Please check this GitHub issue - Job-level "if" condition not evaluated correctly if job in "needs" property is skipped.
I assume that in your case even if you forced job 3 to run the result is not success but something different. Thus job 4 is not run.
You probably need sth like this on job 4.
if: |
always() &&
(needs.job3.result == 'success' || needs.job3.result == 'skipped')
Upvotes: 1