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.
Required roles
To get the permissions that you need to configure Cloud Run jobs, ask your administrator to grant you the following IAM roles:
- Cloud Run Developer (
roles/run.developer) on the Cloud Run job - Service Account User (
roles/iam.serviceAccountUser) on the service identity
For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run job interfaces with Google Cloud APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Configure maximum retries
You can configure maximum retries for a Cloud Run job using the Google Cloud console, the gcloud CLI, YAML, or Terraform:
Console
In the Google Cloud console, go to the Cloud Run page:
Select Jobs from the Cloud Run navigation menu:
If you are creating a new job, click Deploy container to fill out the initial job settings page.
If you are configuring an existing job, select the job, then click View and edit job configuration.
Click Containers, Connections, Security to expand the job properties page.
In the Task capacity section, specify the number of retries using an integer from
0to10.Click Create or Update.
gcloud
To set maximum retries when you create a new job, run the following command:
gcloud run jobs create JOB --image IMAGE_URL --max-retries RETRY
Replace the following:
JOB: the name of your Cloud Run job.IMAGE_URL: a reference to the container image—for example,us-docker.pkg.dev/cloudrun/container/job:latest.RETRY: the number of retries. Specify an integer from0to10.
To update maximum retries for an existing job, run the following command:
gcloud run jobs update JOB --max-retries RETRY
YAML
If you are creating a new job, skip this step. If you are updating an existing job, download its YAML configuration:
gcloud run jobs describe JOB --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_URL maxRetries: RETRY
Replace the following:
JOB: the name of your Cloud Run job.IMAGE_URL: a reference to the container image—for example,us-docker.pkg.dev/cloudrun/container/job:latest.RETRY: the number of retries. Specify an integer from0to10.
Create or update the job using the following command:
gcloud run jobs replace job.yaml
The
gcloud run jobs replacecommand defaults to usingjob.yamlfile if present.
Terraform
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Add the following to agoogle_cloud_run_v2_job
resource in your Terraform configuration:View maximum retries settings
To view the current maximum retries settings for your Cloud Run job, use the Google Cloud console or the Google Cloud CLI:
Console
In the Google Cloud console, go to the Cloud Run jobs page:
Click the job to open the Job details page.
Click View and edit job configuration.
Locate the maximum retries setting in the configuration details.
gcloud
Run the following command:
gcloud run jobs describe JOB
Locate the maximum retries setting in the returned configuration.