Ancestors included in conditional expressions when only parents should be included 🕵️♂️
See original GitHub issueDescribe the bug Given dependant jobs D -> A -> C <- B, and given that A and B might be skipped, I would like C not to run when: a) A and B do not contain at least on successful job, b) any of the jobs including C are cancelled, and c) D has ran successfully
To solve all of these, I have used:
!cancelled() && contains(needs.*.result, 'success')
However, this does not prevent C from running if D is successful even if it is not the direct predecessor in the graph, and C needs only A and B.
To Reproduce Steps to reproduce the behavior:
- Create four jobs A, B, C, and D,
- Configure the needs statement for C to depend on A and B,
- Configure the needs statement for A to depend on D,
- Set the if condition for both A and B to false to force both to skip,
- Set the if condition on C to !cancelled() && contains(needs.*.result, ‘success’),
- Run the workflow,
- Step C is executed even though neither A nor B have successfully ran.
Alternatively, use the following code:
name: Test
on:
push:
jobs:
D:
runs-on: ubuntu-latest
if: true
steps:
- run: echo D
A:
needs: [D]
runs-on: ubuntu-latest
if: false
steps:
- run: echo A
B:
runs-on: ubuntu-latest
if: false
steps:
- run: echo B
C:
runs-on: ubuntu-latest
needs: [A,B]
if: ${{ !cancelled() && contains(needs.*.result, 'success') }}
steps:
- run: echo C
Expected behavior The expression !cancelled() && contains(needs.*.result, ‘success’) should evaluate to false and job C should not run.
Runner Version and Platform
Version of your runner? ubuntu-latest
OS of the machine running the runner? Linux
What’s not working?
Issue Analytics
- State:
- Created 9 months ago
- Comments:5
After review with the team, you can use following example (as you mentioned in above comments)
NEEDS on runner has job1, job2 and job3 and that is why when we echo it we get what we expect, but on service side it has all previous jobs (prep as well) and that’s the problem.
Fair enough, thank you for the update and investigating it. Really appreciate it!