Execute jobs on a schedule

Stay organized with collections Save and categorize content based on your preferences.

This page describes how to execute Cloud Run jobs on a schedule using Cloud Scheduler.

Before you begin

  1. Set up your environment to enable your project to use Cloud Scheduler.

  2. Create a Cloud Run job.

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

  1. Visit the Cloud Scheduler page in the console:

    Cloud Scheduler

  2. Click Create a job.

  3. Under Define a schedule:

    1. Give your job a name.

    2. Select a region for your Cloud Scheduler job. It does not need to match the region used for the Cloud Run job.

    3. Specify the frequency for your job, using the unix-cron format, for example, 0 12 * * *

    4. Select your timezone.

  4. Click Continue.

  5. In the Target type field,

    1. select HTTP from the dropdown menu.

    2. 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.
    3. For HTTP method, select POST. Leave HTTP headers and Body blank.

    4. Click Auth header

    5. Select Add OAuth token.

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

    7. Leave the scope field blank.

  6. Set any desired optional settings.

  7. Click Create.

Command line

  1. Make sure you create a Cloud Run job first.

  2. 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: