TL;DR
Learn how to effectively use GitLab Pipeline Schedules to automate your CI/CD workflows. This guide covers schedule creation, configuration, and best practices.
$1
GitLab Pipeline Schedules allow you to run pipelines at specific intervals, enabling automated builds, deployments, and maintenance tasks. This guide will show you how to effectively use this powerful feature.
$1
$1
$1
$1
1. Navigate to your project's CI/CD settings
2. Select "Schedules"
3. Click "New schedule"
`` nightly_build:
script:
- echo "Running nightly build"
- ./build.sh
only:
- schedules
yaml
`.gitlab-ci.yml
$1
GitLab supports cron syntax for flexible scheduling:
` 0 0 * # Daily at midnight
0 /4 * * # Every 4 hours
0 0 0 # Weekly on Sunday
0 0 1 # Monthly on the 1st
plaintext
`Common cron patterns
$1
$1
` nightly_build:
variables:
ENVIRONMENT: "staging"
BUILD_TYPE: "nightly"
script:
- echo "Building for $ENVIRONMENT"
- ./build.sh --type $BUILD_TYPE
only:
- schedules
yaml
`.gitlab-ci.yml with variables
$1
` deploy_production:
script:
- deploy_to_production.sh
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: manual
- when: never
yaml
`
$1
$1
` stages:
- build
- test
- deploy nightly_staging:
stage: deploy
script:
- deploy_to_staging.sh
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "staging"
when: on_success weekly_production:
stage: deploy
script:
- deploy_to_production.sh
rules:
- if: $CI_PIPELINE_SOURCE == "schedule" && $SCHEDULE_TYPE == "production"
when: manual
yaml
`.gitlab-ci.yml
$1
$1
` schedule_health_check:
script:
- check_system_health.sh
- generate_health_report.sh
artifacts:
reports:
junit: health_report.xml
only:
- schedules
yaml
`Health check job
$1
` nightly_build:
script:
- set -e # Exit on any error
- ./build.sh
after_script:
- |
if [ $CI_JOB_STATUS == "failed" ]; then
notify_team.sh "Nightly build failed"
fi
only:
- schedules
yaml
`
$1
$1
` data_processing:
script:
- process_large_dataset.sh
only:
- schedules
tags:
- high-cpu
variables:
GIT_STRATEGY: none # Skip git clone if not needed
yaml
`Resource-intensive job during off-peak hours
$1
` weekly_backup:
variables:
BACKUP_TYPE: "full"
RETENTION_DAYS: "30"
script:
- backup_database.sh
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: always
tags:
- backup
# Runs every Sunday at 2 AM
only:
variables:
- $SCHEDULE_TYPE == "backup"
yaml
`Well-documented schedule configuration
$1
` .notify_slack: ¬ify_slack
- |
curl -X POST -H 'Content-type: application/json' \
--data "{\"text\":\"Pipeline $CI_PIPELINE_ID: $CI_JOB_STATUS\"}" \
$SLACK_WEBHOOK_URL scheduled_deployment:
script:
- deploy_application.sh
after_script:
- *notify_slack
only:
- schedules
yaml
`Slack notification for scheduled jobs
$1
$1
` stages:
- prepare
- build
- test
- deploy
- notify prepare_environment:
stage: prepare
script:
- setup_environment.sh
only:
- schedules build_application:
stage: build
script:
- build_app.sh
only:
- schedules run_tests:
stage: test
script:
- run_test_suite.sh
only:
- schedules deploy_if_successful:
stage: deploy
script:
- deploy_app.sh
only:
- schedules
when: on_success notify_team:
stage: notify
script:
- send_notification.sh
only:
- schedules
yaml
`Complex scheduled pipeline
$1
` .dynamic_config: &dynamic_config
before_script:
- |
if [ "$SCHEDULE_TYPE" == "backup" ]; then
export BACKUP_PATH="/path/to/backup"
export RETENTION_DAYS=30
elif [ "$SCHEDULE_TYPE" == "cleanup" ]; then
export CLEANUP_PATH="/path/to/cleanup"
export AGE_DAYS=7
fi scheduled_task:
<<: *dynamic_config
script:
- execute_task.sh
only:
- schedules
yaml
`Dynamic configuration based on schedule variables
$1
$1
1. Schedule Not Running
` scheduled_job:
script:
- echo "Schedule Type: $SCHEDULE_TYPE"
- echo "Pipeline Source: $CI_PIPELINE_SOURCE"
- echo "Current Time: $(date)"
- your_actual_script.sh
only:
- schedules
yaml
`Add debug information
2. Timezone Issues
` scheduled_job:
before_script:
- export TZ=UTC
script:
- echo "Current time: $(date)"
- your_actual_script.sh
only:
- schedules
yaml
``Set specific timezone
$1
GitLab Pipeline Schedules are a powerful tool for automating CI/CD workflows. Key takeaways:
$1
1. Implement scheduled pipelines in your projects
2. Explore advanced scheduling patterns
3. Integrate with monitoring systems
4. Optimize resource usage
5. Set up proper notifications
$1
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.