GitHub/rerun: Difference between revisions
< GitHub
(Created page with "== auto-rerun == ref: https://github.com/orgs/community/discussions/67654#discussioncomment-8038649 === test.yml === <pre> test.yml: on: push jobs: fail: runs-on: ubuntu-latest steps: - run: false re-run: needs: fail if: failure() && fromJSON(github.run_attempt) < 3 runs-on: ubuntu-latest steps: - env: GH_REPO: ${{ github.repository }} GH_TOKEN: ${{ github.token }} GH_DEBUG: api run: gh wor...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== auto-rerun == | == auto-rerun == | ||
ref: https://github.com/orgs/community/discussions/67654#discussioncomment-8038649 | * ref: https://stackoverflow.com/questions/71574593/how-to-automatically-retry-github-action-jobs-on-failure | ||
* ref: https://github.com/orgs/community/discussions/67654#discussioncomment-8038649 | |||
* ref: https://medium.com/@aarne.laur/retry-failed-github-actions-8661e7601c66 | |||
something along the lines of: | |||
<pre> | |||
steps: | |||
- name: Rerun failed jobs in the current workflow | |||
env: | |||
GH_TOKEN: ${{ github.token }} | |||
run: gh run rerun ${{ github.run_id }} --failed | |||
</pre> | |||
=== test.yml === | === test.yml === | ||
| Line 46: | Line 57: | ||
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 | gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 | ||
gh run rerun ${{ inputs.run_id }} --failed | gh run rerun ${{ inputs.run_id }} --failed | ||
</pre> | |||
== mikamika == | |||
<pre> | |||
rerun-failed-jobs: | |||
runs-on: ubuntu-latest | |||
needs: [ job1, job2] | |||
if: failure() | |||
steps: | |||
- name: Rerun failed jobs in the current workflow | |||
env: | |||
GH_TOKEN: ${{ github.token }} | |||
run: gh workflow run retry-workflow.yml -F run_id=${{ github.run_id }} | |||
</pre> | |||
-- | |||
<pre> | |||
name: Retry workflow | |||
on: | |||
workflow_dispatch: | |||
inputs: | |||
run_id: | |||
required: true | |||
jobs: | |||
rerun: | |||
runs-on: ubuntu-latest | |||
steps: | |||
- name: rerun ${{ inputs.run_id }} | |||
env: | |||
GH_REPO: ${{ github.repository }} | |||
GH_TOKEN: ${{ github.token }} | |||
run: | | |||
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 | |||
gh run rerun ${{ inputs.run_id }} --failed | |||
</pre> | |||
== medium.com example == | |||
<pre> | |||
name: Feature Branch - Push | |||
on: | |||
push: | |||
branches: | |||
- "feat-*" | |||
jobs: | |||
some-other-step: | |||
runs-on: ubuntu-latest | |||
steps: | |||
- name: This step always fails | |||
run: exit 1 | |||
retry-on-failure: | |||
# only execute the step on failed workflows | |||
# do not trigger more than 3 times | |||
if: failure() && fromJSON(github.run_attempt) < 3 | |||
# run thes step last | |||
needs: [some-other-step] | |||
runs-on: ubuntu-latest | |||
steps: | |||
run: echo "runs only on failure (for maximum of 3 times)" | |||
</pre> | |||
Example 2: | |||
<pre> | |||
# Save this as .github/workflows/retry-workflow.yml | |||
name: Retry workflow | |||
on: | |||
workflow_dispatch: | |||
inputs: | |||
run_id: | |||
required: true | |||
jobs: | |||
rerun: | |||
runs-on: ubuntu-latest | |||
steps: | |||
- name: rerun ${{ inputs.run_id }} | |||
env: | |||
GH_REPO: ${{ github.repository }} | |||
GH_TOKEN: ${{ github.token }} | |||
run: | | |||
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1 | |||
gh run rerun ${{ inputs.run_id }} --failed | |||
</pre> | |||
<pre> | |||
jobs: | |||
retry-on-failure: | |||
if: failure() && fromJSON(github.run_attempt) < 3 | |||
needs: [some-other-step] | |||
runs-on: ubuntu-latest | |||
steps: | |||
- env: | |||
GH_REPO: ${{ github.repository }} | |||
GH_TOKEN: ${{ github.token }} | |||
run: gh workflow run retry-workflow.yml -F run_id=${{ github.run_id }} | |||
</pre> | </pre> | ||
== keywords == | == keywords == | ||
Latest revision as of 10:03, 20 July 2026
auto-rerun
- ref: https://stackoverflow.com/questions/71574593/how-to-automatically-retry-github-action-jobs-on-failure
- ref: https://github.com/orgs/community/discussions/67654#discussioncomment-8038649
- ref: https://medium.com/@aarne.laur/retry-failed-github-actions-8661e7601c66
something along the lines of:
steps:
- name: Rerun failed jobs in the current workflow
env:
GH_TOKEN: ${{ github.token }}
run: gh run rerun ${{ github.run_id }} --failed
test.yml
test.yml:
on: push
jobs:
fail:
runs-on: ubuntu-latest
steps:
- run: false
re-run:
needs: fail
if: failure() && fromJSON(github.run_attempt) < 3
runs-on: ubuntu-latest
steps:
- env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
GH_DEBUG: api
run: gh workflow run rerun.yml -F run_id=${{ github.run_id }}
rerun.yml
on:
workflow_dispatch:
inputs:
run_id:
required: true
jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: rerun ${{ inputs.run_id }}
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
GH_DEBUG: api
run: |
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
gh run rerun ${{ inputs.run_id }} --failed
mikamika
rerun-failed-jobs:
runs-on: ubuntu-latest
needs: [ job1, job2]
if: failure()
steps:
- name: Rerun failed jobs in the current workflow
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run retry-workflow.yml -F run_id=${{ github.run_id }}
--
name: Retry workflow
on:
workflow_dispatch:
inputs:
run_id:
required: true
jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: rerun ${{ inputs.run_id }}
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
run: |
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
gh run rerun ${{ inputs.run_id }} --failed
medium.com example
name: Feature Branch - Push
on:
push:
branches:
- "feat-*"
jobs:
some-other-step:
runs-on: ubuntu-latest
steps:
- name: This step always fails
run: exit 1
retry-on-failure:
# only execute the step on failed workflows
# do not trigger more than 3 times
if: failure() && fromJSON(github.run_attempt) < 3
# run thes step last
needs: [some-other-step]
runs-on: ubuntu-latest
steps:
run: echo "runs only on failure (for maximum of 3 times)"
Example 2:
# Save this as .github/workflows/retry-workflow.yml
name: Retry workflow
on:
workflow_dispatch:
inputs:
run_id:
required: true
jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: rerun ${{ inputs.run_id }}
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
run: |
gh run watch ${{ inputs.run_id }} > /dev/null 2>&1
gh run rerun ${{ inputs.run_id }} --failed
jobs:
retry-on-failure:
if: failure() && fromJSON(github.run_attempt) < 3
needs: [some-other-step]
runs-on: ubuntu-latest
steps:
- env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
run: gh workflow run retry-workflow.yml -F run_id=${{ github.run_id }}