This page describes how to execute Cloud Run jobs on a schedule using Cloud Scheduler.
Before you begin
Set up your environment to enable your project to use Cloud Scheduler.
Use a Cloud Scheduler job to execute a Cloud Run job on a schedule
To create a Cloud Scheduler job that is configured to executes a Cloud Run job on a schedule:
Console
Visit the Cloud Scheduler page in the console:
Click Create a job.
Under Define a schedule:
Give your 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, using the unix-cron format, for example,
0 12 * * *
Select your timezone.
Click Continue.
In the Target type field,
select HTTP from the dropdown menu.
For URL, enter:
https://REGION-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/PROJECT-ID/jobs/JOB-NAME:run
Replace
- REGION with the region for the your Cloud Run job.
- PROJECT-ID with your Google Cloud project ID, for
example,
sample-project
. - JOB-NAME with the name of your Cloud Run job.
For HTTP method, select POST. Leave HTTP headers and Body blank.
Click Auth header
Select Add OAuth token.
Select a service account that has the Cloud Run Invoker role on the Cloud Run job to be triggered, or the Cloud Run Admin, Editor or Owner roles on the project. Note that for a test project, the default compute service account (
PROJECT-NUMBER-compute@developer.gserviceaccount.com
) typically has sufficient permissions. Refer to Access control with IAM for more information.Leave the scope field blank.
Set any desired optional settings.
Click Create.
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-compute@developer.gserviceaccount.com
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.
Cloud Scheduler now runs the Cloud Run job at the specified frequency.
What's next
After you use this feature, you can do the following: