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: stagingGotchas
- 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
How to Gate a Production Deploy With a Manual Job in GitLab CI/CDRequire a human click before a production deploy in GitLab CI/CD with when: manual, optionally making the job…
How to Deploy on a Git Tag With GitLab CI/CDTrigger a production deploy in GitLab CI/CD only when a version tag is pushed by gating the job on CI_COMMIT_…