Skip to content
Latchkey

How to Schedule a Nightly Deploy With GitLab CI/CD

A pipeline schedule fires on a cron timetable, and a rule on CI_PIPELINE_SOURCE runs the deploy only for those scheduled runs.

Create a schedule under CI/CD > Schedules, then gate the deploy job with rules: - if: $CI_PIPELINE_SOURCE == "schedule" so it runs only on the timetable.

Steps

  • Create a schedule in CI/CD > Schedules with a cron and target branch.
  • Gate the deploy job on $CI_PIPELINE_SOURCE == "schedule".
  • Optionally set a schedule-only variable to select the target.
  • Keep push pipelines from triggering the deploy.

.gitlab-ci.yml

.gitlab-ci.yml
nightly_deploy:
  stage: deploy
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
  script:
    - ./deploy.sh --env staging
  environment:
    name: staging

Gotchas

  • Schedules run as the user who owns them; that user needs deploy rights.
  • Cron times use the schedule timezone you pick, not always UTC.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →