Automating Recurring Tasks with GitLab CI/CD Pipeline Schedules
Learn how to implement GitLab CI/CD Pipeline Schedules to automate recurring tasks using Cron syntax and conditional rules to optimize runner usage.
18 Nov 2025, 06:07 UTC

The Problem: Manual Triggers for Routine Maintenance
Many engineering teams rely on manual triggers for tasks like nightly database backups, weekly security scans, or daily environment cleanup. Relying on a human to trigger these pipelines leads to missed windows and inconsistent data. The solution is Pipeline Schedules, which allow you to execute specific branches or tags on a recurring basis using Cron syntax.
Prerequisites
- A GitLab project with a
.gitlab-ci.ymlfile already committed. - An active GitLab Runner configured and available to the project.
- Maintainer or Owner permissions for the project to create and edit schedules.
Configuring the Schedule
Pipeline Schedules are managed through the GitLab UI rather than the YAML configuration file. This separation allows you to change the timing of a job without committing a new code change.
- Navigate to your project and go to Build > Pipeline schedules.
- Select New schedule.
- Description: Provide a clear name (e.g., "Nightly Security Scan").
- Interval Pattern: Select a preset or enter a custom Cron expression. A Cron expression consists of five fields: minute, hour, day of month, month, and day of week.
- Target Branch: Select the branch (e.g.,
mainordevelop) that contains the version of the.gitlab-ci.ymlyou wish to execute. - Variables: Add any key-value pairs needed specifically for this schedule. These will override project-level variables during the scheduled run.
- Click Save pipeline schedule.
Example: Implementing a Weekly Report Job
To ensure a specific job only runs during a schedule (and not on every git push), use the rules keyword in your .gitlab-ci.yml. This prevents unnecessary resource consumption during standard development cycles.
# .gitlab-ci.yml
weekly-report:
script:
- echo "Generating weekly system report..."
- ./scripts/generate_report.sh
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: always
- when: never
In this configuration, the weekly-report job is ignored during merge requests or manual pushes. It only activates when the pipeline is triggered by the GitLab Scheduler.
Diagnostic Checks and Verification
Once the schedule is saved, do not wait for the Cron timer to verify the setup. Use the Play button next to the schedule in the UI to trigger a manual run immediately.
| Check | Expected Result | Location |
|---|---|---|
| Trigger Source | Pipeline status should show "schedule" as the source. | Build > Pipelines |
| Variable Application | Job logs should reflect the values defined in the schedule variables. | Job Log Output |
| Next Run Time | The "Next Run" column should show the correct future timestamp. | Build > Pipeline schedules |
Operational Risks and Limitations
- Runner Minutes: On GitLab.com shared runners, high-frequency schedules (e.g., every 5 minutes) can rapidly deplete your monthly quota.
- Secret Management: Variables defined within the Schedule UI are not encrypted by default. For sensitive data (API keys, passwords), use CI/CD Settings > Variables and mark them as Masked.
- Overlapping Runs: If a scheduled job takes longer to complete than the interval between schedules, multiple instances of the job may run concurrently, potentially causing race conditions in your database or environment.
Rollback and Deactivation
Because schedules do not change the codebase, there is no "rollback" in the traditional sense. To stop a schedule:
- Go to Build > Pipeline schedules.
- Toggle the Active switch to off, or select the Delete icon to remove the schedule entirely.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.