Monitoring GitLab CI scheduled pipelines
GitLab pipeline schedules are a convenient place for nightly builds, backups and data jobs. They also stop quietly. A schedule can be deactivated, can stop running when its owner loses access to the project, or can wait behind busy runners. Failure notifications go to whoever set them up, and only if they're enabled. A heartbeat tells you when the job didn't finish on time, whatever the reason.
Add the pings to the job
Store the ping URL as a CI/CD variable called PING_URL (Settings → CI/CD → Variables), then:
nightly-export:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- curl -fsS -m 10 --retry 3 "$PING_URL/start" || true
- ./scripts/nightly-export.sh
after_script:
- |
if [ "$CI_JOB_STATUS" = "success" ]; then
curl -fsS -m 10 --retry 3 "$PING_URL" || true
else
curl -fsS -m 10 --retry 3 "$PING_URL/fail" || true
fi
after_script runs even when the script fails, and CI_JOB_STATUS tells it how the job
ended. A failure alerts you right away. A schedule that never fires alerts you once the expected time plus the grace
period has passed. The image needs curl.
Match the schedule
Use the same cron expression and timezone as the pipeline schedule (CI/CD → Schedules). Set the grace period to cover runner queue time plus the job's normal duration. The monitor page suggests a grace period from real run times once a few runs are in.
Using GitHub instead? See monitoring GitHub Actions scheduled workflows. Monitor your pipelines. 10 monitors are free.