DevOps / GitLab CI Basics Interview Questions
What are GitLab CI/CD scheduled pipelines and how do you set them up?
Scheduled pipelines run on a defined timetable (like a cron job) without requiring a code push. They are useful for nightly builds, weekly security scans, database backups, and performance benchmarks.
# In .gitlab-ci.yml - detect schedule trigger: nightly-test: stage: test script: - run-full-test-suite.sh rules: - if: $CI_PIPELINE_SOURCE == "schedule" # only runs when scheduled regular-test: stage: test script: - run-quick-tests.sh rules: - if: $CI_PIPELINE_SOURCE != "schedule" # skip during scheduled runs # Variables defined in the schedule are available as CI/CD variables: nightly-deploy: script: - echo "Running type: $PIPELINE_TYPE" # set in schedule config - echo "Env: $DEPLOY_ENV"
Setting up a schedule in the UI:
- Go to Build > Pipeline schedules > New schedule
- Enter a cron expression (e.g.
0 2 * * *for 2am daily) - Select the target branch or tag
- Optionally add custom CI/CD variables for this schedule
- Enable/disable the schedule without deleting it
The $CI_PIPELINE_SOURCE predefined variable equals 'schedule' for scheduled pipelines, allowing you to run different jobs for scheduled vs push-triggered pipelines.
More Related questions...