A Cloud Run job consists of one or more tasks. The maximum retries setting specifies the number of times a task is allowed to restart in case of failure before being failed permanently. The default is 3.
This setting applies per-task, not per-job. If you set this to 0, tasks only run once and are not retried on failure.
To specify maximum retries:
Console
If you are configuring a new job, click the Jobs tab and fill out the initial job settings page as desired. If you are configuring an existing job, click the job, then click Edit.
Click Container, variables and secrets, connections, security to expand the job properties page.
Click the General tab.
Specify the number of retries using an integer from 0 to 10.
Click Create or Update.
Command line
For a job you are creating:
gcloud run jobs create JOB_NAME --image IMAGE_URL --max-retries RETRY
Replace
- JOB_NAME with the name of your job.
- IMAGE_URL with a reference to the container image, for
example,
us-docker.pkg.dev/cloudrun/container/job:latest
. - RETRY with the number of retries: specify an integer from 0 to 10.
For a job you are updating:
gcloud run jobs update JOB_NAME --max-retries RETRY
YAML
Download and view existing job configuration using the
gcloud run jobs describe --format export
command, which yields
cleaned results in YAML format. Then modify the fields described below and
upload the modified YAML using the gcloud run jobs replace
command.
Make sure you only modify fields as documented.
To view and download the configuration:
gcloud run jobs describe JOB_NAME --format export > job.yaml
Update the
maxRetries:
attribute:apiVersion: run.googleapis.com/v1 kind: Job metadata: name: JOB spec: template: spec: template: spec: containers: - image: IMAGE maxRetries: RETRIES
Replace RETRIES with the number of retries: specify an integer from
0
to10
.You can also specify more configuration such as environment variables or memory limits.
Update the existing job configuration:
gcloud run jobs replace job.yaml
Terraform
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
To specify maximum retries for a Cloud Run job, use google_cloud_run_v2_job
resource
and apply the following snippet to your main.tf
file:
View maximum retries settings
To view the current maximum retries settings for your Cloud Run job:
Console
Click the job you are interested in to open the Job details page.
Click the Configuration tab.
Locate the maximum retries setting in the configuration details.
Command line
Use the following command:
gcloud run jobs describe JOB_NAME
Locate the maximum retries setting in the returned configuration.