Github Actions - Is there a way to continue on error while still getting correct feedback?

Viewed 7560

I'm new to Github Actions, and I'm trying to find a way to achieve the following functionality: Whenever a step fails, it will show that it failed (will provide correct feedback) but will still continue to other steps.

At the moment, failure causes the step to stop:

Step's failure prevents next step from starting

I've seen the most popular suggestion is to use continue-on-error, but that seems to make the step's conclusion 'Success', and will not show it failed unless you go into the logs.

Failed step appears to be successful

In the screenshot above, the "Secrets" step failed, and yet it appears to be successful unless entering the logs.

When reading this thread, I came to suspect this feature might not exist yet in GH actions.

I've also tried using conditionals for each step, and/or for the job. For example, I've tried: if: ${{ success() }} || ${{ failure() }} - this simply did not provide the needed functionality, the step failed and the next step did not start.

if: succeeded() || failed() - took this syntax from the Github community thread above, but it generated a syntax error (which makes sense, since it isn't compatible with the syntax specified here).

To conclude, I'm looking for a way to make steps that fail indicate they failed, and still make the workflow continue to the next step.

Thank you!

2 Answers

To my surprise, and thanks to @smac89 for suggesting it - adding if: always() seems to do the trick. I'm still wondering why if: ${{ success() }} || ${{ failure() }} failed, but the solution seems to work for the moment. Thank you for the help!

The continue-on-error is indeed popular, and part of the reason is perhaps that you can set it for each step, or for the whole job. I’m not sure you are aware of this, and this solution was the answer I was looking for.

So this will continue all steps, if either fails:

Job:
  MyRun:
    runs-on: ubuntu-latest

    continue-on-error: true
    
    steps:
      - name: Step One
        run: curl --fail -o dates.csv https://doesnotexist.com/dates.csv
      - name: Step Two
        run: date >> dates.csv

And this will only continue if “Step One” fails, it will break and stop if e.g. “Step Two” fails:

Job:
  MyRun:
    runs-on: ubuntu-latest
    
    steps:
      - name: Step One
        run: curl --fail -o dates.csv https://doesnotexist.com/dates.csv
        continue-on-error: true
      - name: Step Two
        run: date >> dates.csv
Related