Course contentsShow
← Cloud and Infrastructure
Lesson 1699 of 2,98935. GitHub ActionsFree lesson

Schedule-Based Triggers with Cron

Set up workflows that run on a schedule using cron syntax for automated tasks.

Schedule-Based Triggers with Cron

What you'll learn: How to configure GitHub Actions workflows to run automatically at specific times using cron syntax.

Sometimes you need workflows to run on a schedule rather than in response to code changes—think nightly builds, weekly security scans, or daily database backups. GitHub Actions supports this through schedule-based triggers using cron syntax.

What is a Cron-Based Trigger?

Just like setting an alarm clock to wake you at 7 AM every weekday, a cron trigger tells GitHub to start your workflow at predetermined times. You define this schedule in your workflow file using the on.schedule event with cron expressions.

Cron Syntax Basics

Cron uses five fields to specify timing:

* * * * *
│ │ │ │ │
│ │ │ │ └─ Day of week (0-6, Sunday=0)
│ │ │ └─── Month (1-12)
│ │ └───── Day of month (1-31)
│ └─────── Hour (0-23)
└───────── Minute (0-59)

Common Examples:

  • '0 0 * * *' = Daily at midnight UTC
  • '0 9 * * 1' = Every Monday at 9 AM UTC
  • '*/15 * * * *' = Every 15 minutes

Setting Up a Scheduled Workflow

In your workflow file:

on:
  schedule:
    - cron: '0 2 * * *'  # Runs daily at 2 AM UTC

You can define multiple schedules:

on:
  schedule:
    - cron: '0 9 * * 1-5'  # Weekdays at 9 AM
    - cron: '0 0 * * 0'    # Sundays at midnight

Important: GitHub Actions uses UTC time, and scheduled workflows may experience slight delays during high-load periods.

Key Takeaway: Schedule-based triggers with cron let you automate workflows at specific times, perfect for recurring maintenance tasks, reports, or testing without manual intervention.