Skip to content

Commit 0a8a94c

Browse files
Merge pull request #9532 from circleci/DOCSS-1842-automatic-step-reruns
Add docs for automatic step reruns
2 parents 3646389 + 9225baa commit 0a8a94c

File tree

3 files changed

+152
-23
lines changed

3 files changed

+152
-23
lines changed
146 KB
Loading

docs/guides/modules/orchestrate/pages/automatic-reruns.adoc

Lines changed: 98 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
= Automatic workflow reruns
1+
= Automatic reruns
22
:page-platform: Cloud
33
:page-description: Configure automatic reruns for failed workflows to reduce manual intervention and improve pipeline reliability
44
:experimental:
55

6-
Automatic reruns help reduce the impact of temporary failures in your CI/CD pipeline. When a workflow fails due to transient issues, CircleCI can automatically restart the failed workflow without manual intervention.
6+
Automatic reruns help reduce the impact of temporary failures in your CI/CD pipelines. When a workflow fails due to transient issues, CircleCI can automatically restart the failed step or workflow without manual intervention.
77

88
Common use cases include:
99

@@ -12,23 +12,64 @@ Common use cases include:
1212
* Working with spot instances that may be terminated unexpectedly.
1313
* Preventing merge queue delays caused by transient failures.
1414
15-
[#introduction]
1615
== Introduction
1716

18-
Automatic reruns provide a safety net for your CI/CD pipelines by automatically retrying failed workflows. This feature helps teams maintain productivity by reducing the need for manual intervention when workflows fail due to temporary issues.
17+
Automatic reruns provide a safety net for your CI/CD pipelines by automatically retrying failed steps and/or workflows. Automatic reruns help teams maintain productivity by reducing the need for manual intervention when steps and workflows fail due to temporary issues.
1918

20-
The feature works by monitoring workflow completion status and automatically triggering a "rerun from failed" operation when <<rerun-criteria,specific conditions are met>>. This ensures that only failed jobs and their dependencies are retried, while successful jobs from the original workflow are not repeated.
19+
When you configure automatic reruns, CircleCI monitors the status of your pipelines and reruns work as required.
2120

22-
Benefits of automatic workflow reruns include:
21+
Benefits of automatic reruns include:
2322

2423
* Reduced manual intervention for transient failures.
2524
* Improved pipeline reliability and developer productivity.
2625
* Cost-effective retry strategy that only reruns failed jobs.
2726
* Configurable retry limits to prevent infinite loops.
2827

29-
[#quickstart]
3028
== Quickstart
3129

30+
This section provides config examples to help you set up automatic reruns. The content following this quickstart section details how the feature works, along with some troubleshooting guidance and frequently asked questions.
31+
32+
=== Automatic step reruns
33+
34+
To enable automatic reruns for a run step in a job, add the `max_auto_reruns` key to your step with a value between 1 and 5:
35+
36+
NOTE: Automatic reruns are only supported for `run` steps, not special steps like `checkout` or `setup_remote_docker`. Also you must configure the `command` key for the step, you cannot use the short form run step configuration.
37+
38+
.CircleCI config to automatically retry a step up to 3 times if it fails
39+
[source,yaml]
40+
----
41+
version: 2.1
42+
43+
jobs:
44+
my-job:
45+
steps:
46+
- run: echo "Hello, world!"
47+
- run:
48+
command: echo "This step will automatically rerun up to 3 times if it fails"
49+
max_auto_reruns: 3
50+
----
51+
52+
You can add a delay between the step failing and the automatic rerun starting, as follows:
53+
54+
NOTE: If you configure a delay for your automatic step rerun, the delay must be less than or equal to 10 minutes. The delay can be configured as a string with a unit suffix, using `m` (minutes) or `s` (seconds), for example, `auto_rerun_delay: 10s` or `auto_rerun_delay: 3m`. If you do not supply a delay, the rerun will start immediately after the step fails.
55+
56+
.CircleCI config to automatically retry a step up to 3 times if it fails with a 10 second delay between attempts
57+
[source,yaml]
58+
----
59+
version: 2.1
60+
61+
jobs:
62+
my-job:
63+
steps:
64+
- run: echo "Hello, world!"
65+
- run:
66+
command: echo "This step will automatically rerun up to 3 times if it fails with a 10 second delay between attempts"
67+
max_auto_reruns: 3
68+
auto_rerun_delay: 10s
69+
----
70+
71+
=== Automatic workflow reruns
72+
3273
To enable automatic reruns for a workflow, add the `max_auto_reruns` key to your workflow with a value between 1 and 5:
3374

3475
.CircleCI config to automatically retry my-workflow up to 3 times if it fails
@@ -69,23 +110,33 @@ workflows:
69110
[#how-automatic-reruns-work]
70111
== How automatic reruns work
71112

72-
Automatic workflow reruns function similarly to manually clicking "Rerun workflow from failed" in the CircleCI interface. When a workflow fails, CircleCI evaluates whether the workflow qualifies for automatic rerun based on specific criteria, as described in the following section.
113+
Automatic step reruns rerun a full failed step.
114+
115+
Automatic workflow reruns function similarly to manually selecting btn:[Rerun workflow from failed] in the CircleCI web app. When a workflow fails, CircleCI evaluates whether the workflow qualifies for automatic rerun based on specific criteria, as described in the following section.
116+
117+
When both automatic step reruns and automatic workflow reruns are configured together for the same job, the following rules apply:
73118

74-
[#rerun-criteria]
75-
=== Rerun criteria
119+
* The automatic step rerun triggers first.
120+
* If the workflow still fails after all step rerun attempts, the automatic workflow rerun triggers.
76121

77-
For automatic reruns to trigger, all of the following conditions must be met:
122+
=== Automatic rerun criteria
78123

124+
CircleCI monitors *workflow* completion status and automatically triggers a "rerun from failed" operation when the following criteria are met. This ensures that only failed jobs and their dependencies are rerun, while successful jobs from the original workflow are not repeated.
79125
* The workflow status is "failed".
80126
* The `max_auto_reruns` value is specified in the configuration.
81127
* The number of remaining rerun attempts is greater than zero, and less than or equal to the specified `max_auto_reruns` value.
82128
* The workflow is not a manual rerun.
83129
* The pipeline is not older than 90 days.
84130

131+
CircleCI monitors *step* completion status and automatically reruns a failed step when the following criteria are met:
132+
* The step status is "failed".
133+
* The `max_auto_reruns` value is specified for the step in the configuration.
134+
* The number of remaining rerun attempts is greater than zero, and less than or equal to the specified `max_auto_reruns` value.
135+
85136
[#rerun-behavior]
86-
=== Rerun behavior
137+
=== Automatic workflow rerun behavior
87138

88-
When an automatic rerun is triggered:
139+
When an automatic *workflow* rerun is triggered:
89140

90141
* Only failed jobs from the original workflow are retried. If the previous failure blocked dependent jobs from running, these jobs are also run.
91142
* Successfully completed jobs are not rerun.
@@ -99,23 +150,48 @@ CircleCI provides several ways to monitor and track automatic rerun activity.
99150
[#ui-indicators]
100151
=== UI indicators
101152

102-
Automatic reruns are indicated on the pipelines page in the CircleCI web app. In the Trigger event column you sill see *Auto-rerun* followed by the rerun attempt number, as shown in the following screenshot.
153+
Automatic workflow reruns are indicated on the pipelines page in the CircleCI web app. In the Trigger event column you sill see *Auto-rerun* followed by the rerun attempt number, as shown in the following screenshot.
103154

104155
In this example the workflow is rerun twice out of a possible five attempts before it succeeds.
105156

157+
.Automatic workflow reruns in the CircleCI web app
106158
image::guides:ROOT:orchestrate-and-trigger/automatic-rerun.png[Automatic reruns UI]
107159

160+
Automatic step reruns are indicated on the job page in the CircleCI web app.
161+
162+
In this example the run tests step is configured to rerun up to 3 times if it fails with a delay of one minute between attempts.
163+
164+
.Automatic step reruns in the CircleCI web app
165+
image::guides:ROOT:orchestrate-and-trigger/automatic-step-rerun.png[Automatic step reruns UI]
166+
108167
=== Get details via the API
168+
You can get information about automatic reruns via the CircleCI APIs.
109169

110-
You can retrieve information about automatic reruns using the link:https://circleci.com/docs/api/v2/index.html#tag/Workflow/operation/getWorkflowById[CircleCI API]:
170+
==== Automatic workflow reruns
171+
172+
You can retrieve information about *automatic workflow reruns* using the link:https://circleci.com/docs/api/v2/index.html#tag/Workflow/operation/getWorkflowById[CircleCI API v2]:
111173

112174
[source,bash]
113175
----
114176
curl -X GET "https://circleci.com/api/v2/workflow/{workflow-id}" \
115177
-H "Circle-Token: YOUR_TOKEN"
116178
----
117179

118-
The API response includes additional fields for automatic reruns:
180+
The API response includes the following fields for automatic workflow reruns:
181+
182+
* `auto_rerun_number`: The current rerun attempt number.
183+
* `max_auto_reruns`: The maximum number of reruns configured.
184+
185+
==== Automatic step reruns
186+
187+
You can retrieve information about automatic step reruns using the link:https://circleci.com/docs/api/v1/index.html#single-job[job information API endpoint from the CircleCI API v1.1].
188+
189+
[source,bash]
190+
----
191+
curl https://circleci.com/api/v1.1/project/:vcs-type/:username/:project/:build_num -H "Circle-Token: <circle-token>"
192+
----
193+
194+
The API response includes the following fields for automatic step reruns:
119195

120196
* `auto_rerun_number`: The current rerun attempt number.
121197
* `max_auto_reruns`: The maximum number of reruns configured.
@@ -125,10 +201,11 @@ The API response includes additional fields for automatic reruns:
125201

126202
Be aware of these limitations when using automatic workflow reruns:
127203

128-
* Maximum rerun attempts are capped at 5 per workflow.
204+
* Maximum rerun attempts are capped at 5 per step and 5 per workflow.
129205
* Only the original workflow triggers automatic reruns. Manual reruns do not trigger automatic reruns.
130206
* Automatic reruns are disabled if the pipeline is older than 90 days.
131-
* Only failed workflows trigger automatic reruns, not cancelled workflows.
207+
* Only _failed_ workflows trigger automatic reruns, not cancelled workflows.
208+
* Automatic step reruns are only supported for `run` steps, not special steps like `checkout` or `setup_remote_docker`.
132209

133210
[#troubleshooting]
134211
== Troubleshooting
@@ -140,8 +217,8 @@ Common issues and solutions for automatic workflow reruns.
140217

141218
If automatic reruns are not starting, check these conditions:
142219

143-
* Verify `max_auto_reruns` is specified in your workflow configuration.
144-
* Ensure the workflow status is "failed" and not "cancelled".
220+
* Verify `max_auto_reruns` is specified in your configuration.
221+
* Ensure the step or workflow status is "failed" and not "cancelled".
145222
* Confirm the maximum rerun attempts have not been exceeded.
146223
* Check that the workflow was not manually rerun.
147224
* Verify the pipeline is less than 90 days old.
@@ -221,6 +298,4 @@ Automatic reruns start immediately after the workflow fails.
221298
[#faq-step-level]
222299
=== Can I configure automatic reruns at the step level?
223300

224-
NOTE: Step-level configuration for automatic reruns will be supported soon.
225-
226-
Automatic reruns are configured at the workflow level.
301+
Yes, you can configure automatic reruns at the step or workflow level.

docs/reference/modules/ROOT/pages/configuration-reference.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,17 @@ NOTE: the `run` step replaces the deprecated `deploy` step. If your job has a pa
13811381
| N
13821382
| String
13831383
| <<the-when-attribute,Specify when to enable or disable the step>>. Takes the following values: `always`, `on_success`, `on_fail` (default: `on_success`)
1384+
1385+
| `max_auto_reruns`
1386+
| N
1387+
| Integer
1388+
| The maximum number of times to automatically rerun the step if it fails. Must be between `1` and `5`.
1389+
1390+
| `auto_rerun_delay`
1391+
| N
1392+
| String
1393+
| The delay between reruns of the step if it fails. This delay can only be set along with `max_auto_reruns`. The string is a decimal with unit suffix using either seconds `s` or minutes `m` up to a maximum of 10 minutes, such as "10s", "2m".
1394+
13841395
|===
13851396
13861397
Each `run` declaration represents a new shell. It is possible to specify a multi-line `command`, each line of which will be run in the same shell.
@@ -1555,6 +1566,49 @@ A job can exit without failing by using `run: circleci-agent step halt`. However
15551566
15561567
'''
15571568
1569+
==== Automatic step reruns
1570+
1571+
The following attributes can be used to automatically rerun a step if it fails, and delay that rerun if required:
1572+
1573+
[cols="2,1,1,2"]
1574+
|===
1575+
| Key | Required | Type | Description
1576+
1577+
|`max_auto_reruns`
1578+
| N
1579+
| Integer
1580+
| The maximum number of times to automatically rerun the step if it fails. Must be between `1` and `5`.
1581+
1582+
| `auto_rerun_delay`
1583+
| N
1584+
| String
1585+
| The delay between reruns of the step if it fails. This delay can only be set along with `max_auto_reruns`. The string is a decimal with unit suffix using either seconds `s` or minutes `m` up to a maximum of 10 minutes, such as "10s", "2m". If you do not supply a delay, the rerun will start immediately after the step fails.
1586+
|===
1587+
1588+
Automatic reruns are only supported for `run` steps, not special steps like `checkout` or `setup_remote_docker`.
1589+
1590+
You must configure the `command` key for the step, you cannot use the short form run step configuration, for example, the following is not supported for use with automatic reruns: `- run: echo "Hello, world!"`
1591+
1592+
*Example:*
1593+
1594+
.CircleCI job configured to automatically rerun a step up to 3 times if it fails with a 10 second delay between attempts
1595+
[,yml]
1596+
----
1597+
version: 2.1
1598+
1599+
jobs:
1600+
my-job:
1601+
steps:
1602+
- run:
1603+
command: echo "Hello, world!"
1604+
max_auto_reruns: 3
1605+
auto_rerun_delay: 10s
1606+
----
1607+
1608+
For more information, see the xref:guides:orchestrate:automatic-reruns.adoc#[Automatic reruns] page.
1609+
1610+
'''
1611+
15581612
[#the-when-step]
15591613
=== *The `when` step*
15601614

0 commit comments

Comments
 (0)