Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ancestors included in conditional expressions when only parents should be included 🕵️‍♂️

See original GitHub issue

Describe 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:

  1. Create four jobs A, B, C, and D,
  2. Configure the needs statement for C to depend on A and B,
  3. Configure the needs statement for A to depend on D,
  4. Set the if condition for both A and B to false to force both to skip,
  5. Set the if condition on C to !cancelled() && contains(needs.*.result, ‘success’),
  6. Run the workflow,
  7. Step C is executed even though neither A nor B have successfully ran.

Alternatively, use the following code:

name: Test

    runs-on: ubuntu-latest
    if: true
      - run: echo D
    needs: [D]
    runs-on: ubuntu-latest
    if: false
      - run: echo A
    runs-on: ubuntu-latest
    if: false
      - run: echo B
    runs-on: ubuntu-latest
    needs: [A,B]
    if: ${{ !cancelled() && contains(needs.*.result, 'success') }}
      - 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?

Screenshot from 2022-12-29 19-59-55 Screenshot from 2022-12-29 20-00-19

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5

github_iconTop GitHub Comments

ruvceskistefancommented, Jan 12, 2023

After review with the team, you can use following example (as you mentioned in above comments)

    if: |
      always() && 
        needs.A.result == 'success' || 
        needs.B.result == 'success' 

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.

alexandar1000commented, Feb 17, 2023

Fair enough, thank you for the update and investigating it. Really appreciate it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Include or Exclude Ancestors or Descendants of the ...
Specifies the number of ancestors to include or exclude for the subject area. Ancestors are the parents of an entity. Select one of...
Read more >
HierarchyID How to get all Parent from a child
First, you can get your conditional expression in there without a recursive CTE. Second, GetDescendantOf is inclusive so you don't need to ...
Read more >
Reference children, parents, and ancestors with hierarchy ...
ANCESTORS Function Reference all parent cells to a child cell. Hierarchy functions are not supported in cross-sheet formulas. Attempting to use the CHILDREN, ......
Read more >
Can i call my parents and grandparents, ancestors?
No, it's only for relatives further into the past. If you could have known them personally, they're not your ancestor.
Read more >
Proving Parentage | Ancestry - YouTube
Are you still looking for the elusive parents of your great-great-grandfather? Family history isn't just about identifying the birth and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found