Sub topic 10
Continuous deployment: releasing automatically
Continuous deployment is the practice of releasing every change that passes the pipeline to production, with no human approval step. This chapter assumes you know basic Git, can read simple YAML, and have seen a pipeline that builds and tests code. It also assumes you know what continuous delivery is: a pipeline that keeps every change ready to release, with a person pressing the final button.
Delivery versus deployment
The two terms differ by one decision. In continuous delivery, a person decides when to release. In continuous deployment, the pipeline decides. If every automated check passes, the change goes live.
| Aspect | Continuous delivery | Continuous deployment |
|---|---|---|
| Production release | Triggered by a person | Triggered by a passing pipeline |
| Approval gate | Manual, often per release | None per release |
| Release frequency | Chosen by the team | Every merged change |
| Main safety net | Human review plus tests | Tests, monitoring, and fast rollback |
| Typical batch size | Several changes | One change |
Continuous deployment is not a separate toolchain. It is the same pipeline with the manual gate removed. That removal changes what the rest of the pipeline must guarantee.
What you give up and what you gain
Without a manual gate, nobody reads the change one more time before it ships. The pipeline is the only reviewer left. In exchange you get several benefits.
- Small changes. Each release holds one commit or a few. When something breaks, the suspect list is short.
- Fast feedback. Developers see their work in production within minutes, while they still remember it.
- No release day. There is no batching, no release freeze, and no late-night deployment ritual.
- Less waiting. A finished change is not stuck behind someone's calendar.
The cost is that the quality of your automation becomes the quality of your product. A weak test suite is an inconvenience under continuous delivery, because a human may catch the problem. Under continuous deployment, it is a direct path to production incidents.
Prerequisites for removing the gate
Teams that deploy automatically usually have these in place before they remove approval. If any is missing, adding it is a better investment than automating the release.
- A trusted test suite. Tests must be fast, deterministic, and cover the behavior users depend on. A flaky test is dangerous here. Teams learn to ignore failures and rerun until green, and a real defect can slip through that habit.
- Post-deploy verification. Smoke tests run against the live service right after release. They check that the app starts, responds, and can reach its dependencies.
- Monitoring and alerting. You need to see error rates, latency, and saturation in production. Without that, a bad release can run for hours unnoticed.
- Fast, tested rollback. You must be able to return to the previous version in minutes, and you must have practiced it.
- Small, reversible changes. Big-bang changes and irreversible database changes do not fit this model.
- Safe rollout mechanisms. Deployment strategies such as rolling, blue/green, and canary limit how many users a bad release can reach. Feature flags separate deploying code from turning it on. Later chapters cover both.
A pipeline with no approval step
The following workflow builds, tests, deploys, and verifies on every push to main. It differs from the two-job pipeline shown earlier in the tutorial in that the production environment has no required reviewers. scripts/deploy.sh and scripts/smoke-test.sh are placeholders for your own scripts.
name: continuous-deployment
on:
push:
branches: [main]
concurrency:
group: production-deploy
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm test
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
deploy:
needs: build
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- run: ./scripts/deploy.sh dist/
- run: ./scripts/smoke-test.shThree details matter.
needs: buildmeans the deploy job never starts if tests or the build fail. This is the automatic gate that replaces the human one.- The
concurrencyblock serializes production deployments. If two merges land close together, the second waits for the first to finish. Settingcancel-in-progress: falseavoids killing a deployment halfway through, which could leave production in a mixed state. - The smoke test is the last step. If it exits with a non-zero status, the job fails and the team is notified. You can extend the script to roll back automatically on failure.
Handling failures after release
Tests before release cannot catch everything. Production has real traffic, real data, and real dependencies. Plan for a bad release instead of assuming it will not happen.
There are two broad responses.
- Roll back. Redeploy the last known good artifact. Because the pipeline builds once and keeps artifacts, this is usually a matter of rerunning the deploy step with an older artifact.
- Roll forward. Merge a small fix and let the pipeline ship it. This works well when the fix is obvious and the pipeline is fast, but it depends on your pipeline being quick enough that users are not hurt while you wait.
Whichever you choose, you should detect problems automatically. A health check after deployment can trigger rollback without a person in the loop.
#!/usr/bin/env bash
set -euo pipefail
URL="https://example.com/health"
for attempt in 1 2 3 4 5; do
if curl --fail --silent --max-time 5 "$URL" > /dev/null; then
echo "Healthy on attempt $attempt"
exit 0
fi
echo "Attempt $attempt failed, retrying"
sleep 5
done
echo "Health check failed" >&2
exit 1This script retries a health endpoint five times. A non-zero exit fails the pipeline step, which can then call your rollback procedure.
Edge cases
Database changes
Code can be rolled back by redeploying the old version. Data usually cannot. If a release drops a column, rolling back the code does not bring the column back. The standard approach is the expand and contract pattern. First add the new structure while the old code still works. Then deploy code that uses the new structure. Remove the old structure in a later release, once nothing depends on it. Each step is safe to deploy alone and safe to roll back.
Overlapping versions
During a rolling or canary release, old and new versions run at the same time. They share a database and may share message queues. Both versions must tolerate each other's data formats.
Changes that need coordination
Some changes need a launch date, a marketing announcement, or a matching update in another team's system. Feature flags handle this. You deploy the code continuously, with the feature off, and switch it on when the business is ready. Deployment and release become separate decisions.
Regulated environments
Some regulations require a documented approval before production changes. You do not always have to give up automation. Automated checks, signed artifacts, and an auditable pipeline log can satisfy many controls, but check your actual requirements. Where a human approval is mandatory, continuous delivery is the right model.
Not every service needs it
Continuous deployment fits web services with fast rollback. It fits poorly where a release cannot be undone or reaches users slowly, such as mobile apps awaiting store review, firmware, or embedded devices. Those teams often stay at continuous delivery and apply the same discipline to a release train.
Common mistakes
- Removing the gate before building trust. Teams skip the prerequisites and treat the first outage as proof the practice fails. Remove approval after tests and monitoring are solid.
- Ignoring flaky tests. A suite people rerun until it passes cannot protect production.
- Skipping post-deploy checks. A green pipeline means the code deployed, not that it works. Verify the live service.
- Untested rollback. A rollback procedure you have never run may fail when you need it.
- Letting
mainstay broken. Under continuous deployment, a brokenmainis a broken production. Fix or revert immediately. - Letting deploys overlap. Without concurrency control, two pipelines can write to production at once.
Exercises
Exercise
A team deploys to production on every merge to main. Their test suite fails randomly about one run in ten, and developers usually click "rerun" until it passes. Why is this a problem specifically for continuous deployment, and what should the team do first?
Show answer
With no human gate, the test suite is the only barrier before production. Habitual reruns teach people to ignore failures, so a real defect can be mistaken for flakiness and ship. The team should find and fix or quarantine the flaky tests first, so that a red build always means a real problem. Only then is it safe to rely on the pipeline alone.
Exercise
In the pipeline in this chapter, why is cancel-in-progress set to false for the production concurrency group?
Show answer
If a newer merge cancelled a deployment that was already running, production could be left half updated. Setting it to false makes the newer run wait until the current deployment finishes, so deployments happen one at a time and each one completes.
Exercise
A release drops a database column, and the code that stopped using it ships in the same release. The release fails and you roll back the code. What goes wrong, and how does the expand and contract pattern prevent it?
Show answer
The old code expects the column, but it has been dropped, so the rolled-back version fails. With expand and contract, you first deploy code that no longer needs the column while the column still exists. Only in a later release, after nothing depends on the column, do you remove it. Each step can be rolled back without losing data the old code needs.