question-mark
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.

if conditional evaluated wrong for contains(needs.*.result, 'failure')

See original GitHub issue

Describe the bug A job-level if conditional isn’t evaluated properly when using the contains function and array wildcard syntax.

For example, if contains(needs.*.result, 'failure') evaluates to false, a job with if: always() && contains(needs.*.result, 'failure') will run, but a job with if: always() && (needs.job_a.result == 'failure' || needs.job_b.result == 'failure') won’t run.

To Reproduce

  1. Run a workflow with the following yaml configuration. Examining the output reveals that: a. Job a fails b. Job b is skipped c. Job c is skipped d. Job d runs (unexpected) even though contains(needs.*.result, 'failure') evaluates to false
jobs:
  a:
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "This job fails."
          exit 1
  b:
    runs-on: ubuntu-latest
    if: ${{ false }}
    needs: a
    steps:
      - run: echo "This job never happens."
  c:
    runs-on: ubuntu-latest
    if: ${{ false }}
    needs: [a, b]
    steps:
      - run: echo "This job never happens."
  d:
    runs-on: ubuntu-latest
    needs: [b, c]
    if: always() && contains(needs.*.result, 'failure')
    steps:
      - run: |
          echo "I don't want this to run unless b or c fails!"
          echo ${{ contains(needs.*.result, 'failure') }}   # Evaluates to false!

image

  1. However, running a workflow with the following yaml has the expected outcome: a. Job a fails b. Job b is skipped c. Job c is skipped d. Job d is skipped (expected)
jobs:
  a:
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "This job fails."
          exit 1
  b:
    runs-on: ubuntu-latest
    if: ${{ false }}
    needs: a
    steps:
      - run: echo "This job never happens."
  c:
    runs-on: ubuntu-latest
    if: ${{ false }}
    needs: [a, b]
    steps:
      - run: echo "This job never happens."
  d:
    runs-on: ubuntu-latest
    needs: [b, c]
    if: always() && (needs.b.result == 'failure' || needs.c.result == 'failure')  # ONLY CHANGE
    steps:
      - run: |
          echo "I don't want this to run unless b or c fails!"
          echo ${{ contains(needs.*.result, 'failure') }}   # Evaluates to false!

image

Expected behavior if: always() && contains(needs.*.result, 'failure') should have the same behavior as if: always() && (needs.b.result == 'failure' || needs.c.result == 'failure'). In other words, if: always() && contains(needs.*.result, 'failure') should evaluate to false and job d should be skipped.

Runner Version and Platform

Version of your runner? Not sure - running with GitHub Actions (not self-hosted runner)

OS of the machine running the runner? ubuntu-latest

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kvfairchildcommented, Apr 3, 2023

Just hopping on to hopefully encourage some movement on this issue; I spent way too long debugging my workflow before finding the solution in this thread.

1reaction
dbarbiercommented, Dec 15, 2021

Hi there, not related to the original issue, but could this inconsistency with respect to indirect dependencies please be fixed? The same condition could pass at the job level but not at the step level, this is error prone: I spent some time debugging a workflow because of that. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitHub-actions OR operator for needs clause
Yes it's possible. Unfortunately I have some cases where it doesn't always works as expected. But the idea is to do something as...
Read more >
Conditions - Azure Pipelines
Even if a previous dependency has failed, unless the run was canceled. Use succeededOrFailed() in the YAML for this condition.
Read more >
How To Write Conditional Statements in JavaScript
An if statement will evaluate whether a statement is true or false, and only run if the statement returns true . The code...
Read more >
How to use Java's conditional operator ?:
The Java ternary operator provides an abbreviated syntax to evaluate a true or false condition, and return a value based on the Boolean ......
Read more >
Pipeline failure and error message - Azure Data Factory
We determine pipeline success and failures as follows: Evaluate outcome for all leaves activities. If a leaf activity was skipped, ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found