How to Run a Smoke Test After Deploy in GitLab CI
A smoke job in a stage after deploy curls the live endpoint with retries and fails the pipeline if it never recovers.
Add a smoke stage after deploy. The job polls a health/canary endpoint with backoff and exits non-zero if it never returns healthy.
Poll health after deploy
The smoke job runs in the stage after deploy and fails the pipeline if the endpoint stays unhealthy.
.gitlab-ci.yml
stages: [deploy, smoke]
deploy:
stage: deploy
script:
- ./deploy.sh
smoke:
stage: smoke
image: curlimages/curl:8.8.0
script:
- |
for i in $(seq 1 10); do
code=$(curl -s -o /dev/null -w '%{http_code}' https://app.example.com/healthz)
[ "$code" = "200" ] && exit 0
sleep 6
done
echo "Smoke check failed" && exit 1Gotchas
- Put smoke in a later stage (or use
needs: [deploy]) so it only runs once the deploy job succeeded. - Poll with backoff - the release may need a few seconds before the health endpoint reports ready.
- Combine with a rollback job using
when: on_failureso a failed smoke test triggers remediation automatically.
Related guides
How to Run a Smoke Test After Deploy in GitHub ActionsRun a post-deploy smoke test in GitHub Actions as a job that needs the deploy, polling a health endpoint and…
How to Deploy to Kubernetes from GitLab CIDeploy to Kubernetes from GitLab CI with a kubectl image, a masked kubeconfig variable, and kubectl rollout s…