Sub topic 7
Verifying a Deployment Before Promoting Further
This chapter assumes you know basic Git, CI concepts, containers, and YAML. It also assumes you have read the earlier chapters on immutable artifacts and the promotion pipeline. Here you will learn how a pipeline decides that a deployment to staging is healthy enough for the same build to move on to production.
Why a green deploy is not enough
A deploy job can succeed while the application is broken. The script ran, the image was swapped, and the exit code was 0. That says nothing about whether users can log in or whether the app can reach its database.
Verification closes that gap. It is a set of automated checks that run against the deployed environment, after the deploy and before the next promotion. If any check fails, the pipeline stops and the build never reaches production.
Two layers of checks
Most pipelines combine two layers.
| Layer | Question it answers | Typical cost |
|---|---|---|
| Rollout check | Did the new version start and become ready? | Seconds |
| Smoke test | Do the most important paths work? | Seconds to a minute |
| Integration test | Do components and external services work together? | Minutes |
A rollout check comes from the platform. In the deploy.sh script from this tutorial, kubectl rollout status --timeout=120s waits until the new pods are ready. It fails the job if they are not. With set -euo pipefail, that failure stops the script and fails the job.
A smoke test is a short set of requests against the live environment. It covers only what must work: the health endpoint, a login, one read, and one write. An integration test is broader. It exercises real dependencies such as the database or a payment sandbox.
Check that you are testing the right version
A common error is a smoke test that passes against the old version. During a rolling update, old and new instances serve traffic together. A request may reach an old instance and succeed.
Have the application report its build identifier, then compare it with the one you deployed. This also supports the traceability goal covered later.
#!/usr/bin/env bash
# smoke.sh <base-url> <expected-image-tag>
set -euo pipefail
base_url="$1"
expected="$2"
# 1. The service answers its health endpoint.
curl --fail --silent --show-error --max-time 10 "$base_url/healthz" > /dev/null
# 2. The service reports the build we just deployed.
actual="$(curl --fail --silent --show-error --max-time 10 "$base_url/version")"
if [ "$actual" != "$expected" ]; then
echo "Expected version $expected but found $actual" >&2
exit 1
fi
echo "Smoke test passed for $expected"The script assumes the application exposes /healthz and /version. curl --fail makes HTTP errors return a nonzero exit code, so the job fails on a 500.
Wiring verification into the pipeline
Add a verification job between staging and production. Production then depends on verification, not only on the staging deploy.
verify-staging:
needs: [build, deploy-staging]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./smoke.sh https://staging.example.com "${GITHUB_SHA}"
deploy-production:
needs: [build, verify-staging]
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- run: ./deploy.sh production "${{ needs.build.outputs.image }}"Because deploy-production lists verify-staging in needs, a failed smoke test skips it. This sketch assumes the /version endpoint returns the commit SHA. If your application reports something else, pass that value instead.
Make the checks trustworthy
Verification is only useful if people believe it. Keep these points in mind.
- Fail loudly. A check that cannot reach the environment must fail, not skip.
- Avoid flaky tests. A test that fails at random teaches the team to rerun until green. Use timeouts and short retries for startup delay, and fix the tests that fail on their own.
- Use safe test data. Checks that write data should use dedicated test accounts and clean up after themselves.
- Keep it fast. Run smoke tests on every promotion. Run slower integration suites in parallel or on a schedule, and gate on them only if they are reliable.
- Verify production too. Run the same smoke test after the production deploy. Staging passing does not prove production is healthy, because the environments differ in configuration and data.
Exercise
A smoke test passes in staging during a rolling update, but the new version turns out to be broken. Give one likely cause and one way to prevent it.
Show answer
The request probably hit an old instance that was still serving traffic. Prevent it by waiting for the rollout to finish before testing, and by having the test compare the version reported by the service with the expected build identifier.
Exercise
Why should the production deploy job depend on the verification job and not only on the staging deploy job?
Show answer
A successful deploy only means the release steps ran. Depending on the verification job means production starts only if automated checks confirmed the staging deployment works.