intermediate 12 min read

How to Set Up Cron Jobs on Google Cloud (Cloud Scheduler)

Learn how to schedule cron jobs on Google Cloud using Cloud Scheduler. Covers targeting Cloud Functions, Cloud Run, Pub/Sub, and HTTP endpoints.

Prerequisites

  • Google Cloud account
  • gcloud CLI configured
  • A target service (Cloud Function, Cloud Run, or HTTP endpoint)

What Is Cloud Scheduler?

Google Cloud Scheduler is a fully managed cron service. It triggers targets on a schedule — Cloud Functions, Cloud Run services, Pub/Sub topics, or arbitrary HTTP endpoints.

It uses standard Unix cron syntax (5 fields) and supports IANA timezone names. You get 3 free jobs per month, then $0.10/job/month after that.

Quick Start with gcloud CLI

Create a job targeting an HTTP endpoint:

bash
gcloud scheduler jobs create http my-job \
  --schedule="0 9 * * 1-5" \
  --uri="https://my-app.run.app/api/daily-task" \
  --http-method=POST \
  --time-zone="America/New_York" \
  --location=us-central1

Trigger a Cloud Function:

bash
gcloud scheduler jobs create http my-function-job \
  --schedule="*/5 * * * *" \
  --uri="https://us-central1-my-project.cloudfunctions.net/myFunction" \
  --http-method=POST \
  --oidc-service-account-email=scheduler-sa@my-project.iam.gserviceaccount.com

Publish to Pub/Sub:

bash
gcloud scheduler jobs create pubsub my-pubsub-job \
  --schedule="0 */6 * * *" \
  --topic=my-topic \
  --message-body='{"action": "cleanup"}' \
  --time-zone="UTC"

Common Cron Expressions

Standard 5-field Unix cron format:

  • */5 * * * * — Every 5 minutes
  • 0 * * * * — Every hour
  • 0 0 * * * — Daily at midnight
  • 0 9 * * 1-5 — Weekdays at 9 AM
  • 0 0 1 * * — First day of every month
  • 0 0 * * 0 — Every Sunday at midnight

Cloud Scheduler also supports timezone-aware scheduling — set the timezone when creating the job.

Every weekday at 9:00 AM

Next runs (UTC):

Mon, May 18, 2026 09:00

Tue, May 19, 2026 09:00

Wed, May 20, 2026 09:00

Targeting Different Services

Cloud Scheduler can target three types of endpoints:

HTTP (Cloud Functions, Cloud Run, any URL):

bash
gcloud scheduler jobs create http job-name \
  --schedule="0 9 * * *" \
  --uri="https://my-service.run.app/cron" \
  --http-method=POST \
  --headers="Content-Type=application/json" \
  --body='{"task":"cleanup"}'

Pub/Sub (for decoupled architectures):

bash
gcloud scheduler jobs create pubsub job-name \
  --schedule="0 * * * *" \
  --topic=my-topic \
  --message-body='trigger'

App Engine HTTP:

bash
gcloud scheduler jobs create app-engine job-name \
  --schedule="0 0 * * *" \
  --service=my-service \
  --relative-url=/cron/daily

Retry Configuration

Cloud Scheduler retries failed jobs automatically. Configure retry behavior:

bash
gcloud scheduler jobs create http my-job \
  --schedule="0 9 * * *" \
  --uri="https://my-app.run.app/task" \
  --attempt-deadline=300s \
  --max-retry-attempts=3 \
  --min-backoff=5s \
  --max-backoff=1h \
  --max-doublings=5
  • attempt-deadline — Max time to wait for a response (default: 30 minutes)
  • max-retry-attempts — Number of retries (0 = no retries, -1 = unlimited)
  • Backoff — Exponential backoff between retries

Managing Jobs

bash
# List all jobs
gcloud scheduler jobs list --location=us-central1

# Describe a job
gcloud scheduler jobs describe my-job --location=us-central1

# Run a job immediately (for testing)
gcloud scheduler jobs run my-job --location=us-central1

# Pause a job
gcloud scheduler jobs pause my-job --location=us-central1

# Resume a paused job
gcloud scheduler jobs resume my-job --location=us-central1

# Update schedule
gcloud scheduler jobs update http my-job \
  --schedule="0 10 * * *" --location=us-central1

# Delete a job
gcloud scheduler jobs delete my-job --location=us-central1

Production Tips

Authentication: Use OIDC tokens for Cloud Functions/Cloud Run targets:

bash
gcloud scheduler jobs create http my-job \
  --schedule="0 * * * *" \
  --uri="https://my-service.run.app/cron" \
  --oidc-service-account-email=scheduler@project.iam.gserviceaccount.com

Monitoring: Cloud Scheduler logs all executions to Cloud Logging. Set up alerts for job failures:

bash
gcloud logging read 'resource.type="cloud_scheduler_job" AND severity>=ERROR' --limit=10

Cost: 3 free jobs/month per billing account. Additional jobs are $0.10/job/month. Execution is free — you only pay for the target service (Cloud Functions, Cloud Run, etc.).

Frequently Asked Questions