Skip to content
Latchkey

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 1

Gotchas

  • 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_failure so a failed smoke test triggers remediation automatically.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →