DEV Community

zhihu wu
zhihu wu

Posted on • Originally published at codetoolbox.pro

Cron Expressions for CI/CD — Beyond Crontab Basics

Most developers first encounter cron through crontab -e on a Linux server. But cron syntax now powers schedules far beyond sysadmin scripts — it's the backbone of CI/CD automation.

Cron in the Modern Stack

Three tools you probably use today rely on cron expressions:

GitHub Actions. The schedule trigger uses standard 5-field cron. This runs every weekday at 6 AM UTC:

on:
  schedule:
    - cron: '0 6 * * 1-5'
Enter fullscreen mode Exit fullscreen mode

Kubernetes CronJobs. Same syntax, different YAML:

apiVersion: batch/v1
kind: CronJob
spec:
  schedule: "*/15 * * * *"
Enter fullscreen mode Exit fullscreen mode

AWS EventBridge / CloudWatch. Cloud-native cron for serverless triggers.

The Trick People Miss

When both day-of-month AND day-of-week are specified (not *), cron uses OR logic — the job fires when EITHER matches. This catches everyone:

0 0 1 * 1 doesn't mean "the 1st of the month only if it's Monday." It means "run at midnight on the 1st of every month, AND also every Monday." If you meant the first scenario, set day-of-week to * and add date-checking logic in your script.

Quick Testing Tip

Instead of waiting to see if your cron fires, use a visual generator to confirm the intent. I use CodeToolbox's Cron Expression Generator — pick the fields from dropdowns, read the plain-English description, and check the next 5 execution times before pasting into CI config. All browser-side, no signup needed.

What cron mistake taught you a lesson the hard way?

Top comments (0)