Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 218
georgek24 Avatar asked May 27 '20 14:05

georgek24


People also ask

Is GitHub Actions better than Travis?

Conclusion. The best platform for you all depends on your specific needs. If you host your code somewhere other than GitHub.com or GitHub Enterprise, you will be better off using Travis CI. However, if you host your code on GitHub.com or GitHub Enterprise, the choice can be a little more difficult.

Are GitHub Actions reliable?

GitHub actions have some good default security measures built in, but you can do more to protect yourself. GitHub Actions 1 are programs designed to run inside of workflows 2, triggered by specific events inside a GitHub repository.

How do I rerun actions on GitHub?

Re-running all the jobs in a workflowIn the left sidebar, click the workflow you want to see. From the list of workflow runs, click the name of the run to see the workflow run summary. In the upper-right corner of the workflow, use the Re-run jobs drop-down menu, and select Re-run all jobs.

Can I have a GitHub action step run that might fail?

I wanted to have a GitHub Action step run that might fail, but if it failed the rest of the steps should still execute and the overall run should be treated as a success. Skip to primary navigation Skip to content Skip to footer An independent mind... Portfolio Posts Categories Tags About Toggle searchToggle menu Francis T. O'Donovan

What is a GitHub action?

GitHub Actions Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you'd like, including CI/CD, and combine actions in a completely customized workflow.

Does continue-on-error work with failed tasks?

I described that solution in the original question, but this doesn't work in my case, because with continue-on-error, a failed task will still cause the overall build to pass. And i still wanted failed builds to be marked as failed, while still running this task regardless of the previous tasks.

How do I cancel a workflow in Git?

In other words, one can simply use: if: always (). Note that this has the unwanted side effect that you can no longer manually cancel your workflow: docs.github.com/en/actions/managing-workflow-runs/… Contrary to if: always (), if: success () || failure () keeps the ability to cancel builds while still achieving the OPs goal.


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!

like image 70
georgek24 Avatar answered Oct 18 '22 23:10

georgek24


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
like image 4
MS Berends Avatar answered Oct 18 '22 23:10

MS Berends