Skip to content
Latchkey

Conditional skip of a scheduled run by branch in CI

Since a schedule always runs on the default branch, a branch-based if like github.ref == 'refs/heads/develop' will never match under cron. Skip scheduled runs using the event name, the repository, or a job-level guard instead.

What this error means

A step guarded by a branch condition never runs under the schedule, or a scheduled run executes in a fork you did not intend it to run in.

.github/workflows/nightly.yml
# This never runs on schedule because the ref is the default branch:
- if: github.ref == 'refs/heads/develop'
  run: ./nightly.sh

Common causes

Branch conditions do not match under schedule

The schedule ref is the default branch, so any non-default branch condition evaluates false and skips the step.

No guard against running in forks

Without a repository check, a scheduled job can run in forks you did not intend.

How to fix it

Guard on event name and repository

  1. Use github.event_name == 'schedule' to detect cron runs.
  2. Add github.repository == 'owner/repo' to skip forks.
  3. Avoid non-default-branch conditions for scheduled steps.
.github/workflows/nightly.yml
- if: github.event_name == 'schedule' && github.repository == 'acme/app'
  run: ./nightly.sh

Skip with a job-level condition

Gate the whole job so it only runs on the intended repository and event.

.github/workflows/nightly.yml
jobs:
  nightly:
    if: github.event_name == 'schedule'
    runs-on: ubuntu-latest

How to prevent it

  • Never use non-default-branch conditions for scheduled steps.
  • Guard forks with a repository check.
  • Prefer event-name conditions for cron-specific logic.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →