'How to automatically retry github action jobs on failure?

I am building github action pipelines, I want to add an auto retry to my jobs similar to how the retry keyword works in gitlab, where on failure the full step will be run again. Is there anything in github actions that allows this?

Here is an example job I am using:

jobs:
  env-check:
    runs-on: ubuntu-latest
    container:
      image: myimage
    steps:
      - uses: actions/checkout@v2
      - name: env-check
        run: |
          echo "foobar"


Solution 1:[1]

There does not seem to be a retry in GitHub Action syntax, which is why you find complementary GitHub Actions like:

  • Retry Step: Retries an Action step on failure or timeout. This is currently intended to replace the run step for moody commands.
  • Retry Action: Retries an Github Action step or command on failure.

Example:

uses: nick-fields/retry@v2
with:
  timeout_minutes: 10
  max_attempts: 3
  command: npm run some-typically-slow-script

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC