This page describes how to execute Cloud Run jobs on a schedule using Cloud Scheduler.
Required roles
To get the permissions that you need for the operations described on this page, ask your administrator to grant you the IAM roles on your Cloud Run job:
- Cloud Scheduler Admin
(
roles/cloudscheduler.admin
), or a custom role with thecloudscheduler.jobs.create
permission - Cloud Run Invoker (
roles/run.invoker
) to execute jobs using the Google Cloud CLI, or Cloud Run Developer (roles/run.developer
) to execute jobs using the Google Cloud console
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.
Before you begin
Configure a Cloud Run job to execute on a schedule
To execute a Cloud Run job on a schedule:
Console
Click the job you want to execute on a schedule.
Click the Triggers tab.
Click Add Scheduler Trigger.
If you haven't yet enabled the Cloud Scheduler API for your project, you are prompted to do so in the far right panel: click Enable API.
Fill out the Cloud Scheduler job form
Under Define a schedule:
Give your Cloud Scheduler job a name.
Select a region for your Cloud Scheduler job. It does not need to match the region used for the Cloud Run job.
Specify the frequency for your job execution, using the unix-cron format, for example,
0 12 * * *
Select your timezone.
Click Continue.
In the Service Account dropdown menu, select a service account that has the permission to invoke the current Cloud Run service.
Click Create to create the Cloud Scheduler job that will execute the Cloud Run job at the specified frequency.
Command line
Make sure you create a Cloud Run job first.
Run the command:
gcloud scheduler jobs create http SCHEDULER_JOB_NAME \ --location SCHEDULER_REGION \ --schedule="SCHEDULE" \ --uri="https://CLOUD_RUN_REGION-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/PROJECT-ID/jobs/JOB-NAME:run" \ --http-method POST \ --oauth-service-account-email PROJECT-NUMBER[email protected]
Replace
- SCHEDULER_JOB_NAME with the name you want to give your scheduler job.
- SCHEDULER_REGION with a region supported by
Cloud Scheduler, for example,
europe-west2
. - CLOUD_RUN_REGION with the region for the your Cloud Run
job. For preview, use
europe-west9
. - SCHEDULE with the desired frequency, for example
0 12 * * *
- PROJECT-ID with your project ID.
- PROJECT-NUMBER with your project number.
- JOB-NAME with your Cloud Run job.
Terraform
To create a Cloud Scheduler job that executes a Cloud Run job:
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Cloud Scheduler will execute the Cloud Run job at the specified frequency.
What's next
After you use this feature, you can do the following: