Set maximum retries for jobs

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:

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

To specify maximum retries:

Console

  1. In the Google Cloud console, go to the Cloud Run jobs page:

    Go to Cloud Run

  2. Select Jobsfrom the menu, and click Deploy containerto fill out the initial job settings page. If you are configuring an existing job, select the job, then click Edit.

  3. Click Container(s), Volumes, Connections, Securityto expand the job properties page.

  4. Click the Generaltab.

    image

    • Specify the number of retries using an integer from 0 to 10.
  5. Click Createor Update.

gcloud

  1. 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 : 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.
  2. For a job you are updating:

    gcloud  
    run  
     jobs 
      
    update  
     JOB_NAME 
      
    --max-retries  
     RETRY 
    

YAML

  1. 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_NAME 
      
    --format  
     export 
      
    >  
    job.yaml
  2. 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 to 10 .

    You can also specify more configuration such as environment variables or memory limits.

  3. 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 .

Add the following to a google_cloud_run_v2_job resource in your Terraform configuration:
  resource 
  
 "google_cloud_run_v2_job" 
  
 "default" 
  
 { 
  
 name 
  
 = 
  
 "cloud-run-job-retries" 
  
 location 
  
 = 
  
 "us-central1" 
  
 deletion_protection 
  
 = 
  
 false 
 # set to "true" in production 
  
 template 
  
 { 
  
 template 
  
 { 
  
 max_retries 
  
 = 
  
 3 
  
 containers 
  
 { 
  
 image 
  
 = 
  
 "us-docker.pkg.dev/cloudrun/container/job:latest" 
  
 } 
  
 } 
  
 } 
 } 
 

View maximum retries settings

To view the current maximum retries settings for your Cloud Run job:

Console

  1. In the Google Cloud console, go to the Cloud Run jobs page:

    Go to Cloud Run jobs

  2. Click the job you are interested in to open the Job detailspage.

  3. Click View and Edit job configuration.

  4. Locate the maximum retries setting in the configuration details.

gcloud

  1. Use the following command:

    gcloud  
    run  
     jobs 
      
    describe  
     JOB_NAME 
    
  2. Locate the maximum retries setting in the returned configuration.

Create a Mobile Website
View Site in Mobile | Classic
Share by: