Sub topic 10
Continuous deployment: releasing automatically
This chapter assumes you can read simple YAML, use Git branches and pull requests, and know how a basic pipeline builds and tests code. It also assumes you have seen continuous delivery, where every change is ready to release but a person decides when to ship.
What continuous deployment means
Continuous deployment is the practice of releasing every change that passes the pipeline to production automatically. No person clicks a button. If the tests pass, the change goes live.
The difference from continuous delivery is a single step. In continuous delivery, a human approves the release. In continuous deployment, the pipeline's checks are the approval.
Turning delivery into deployment
Take the two-job pipeline from the previous chapters. Its deploy job uses environment: production. If you configure that environment in the repository settings to require reviewers, the job waits for a person. That is continuous delivery.
To get continuous deployment, remove the required reviewers. The workflow file does not change. The deploy job then starts as soon as build succeeds.
name: ci-cd
on:
push:
branches: [main]
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/Here scripts/deploy.sh is a placeholder for your own deploy script. With no approval rule on production, every merge to main that passes the tests reaches users.
What you need before you can do this
Removing the human gate moves all the safety work into the system. These conditions should hold first:
- Trustworthy tests. The test suite must catch the failures you care about. Flaky or thin tests turn automation into a fast way to ship bugs.
- Small changes. Small commits are easier to verify and to undo than large batches.
- Safe release mechanics. You need a deployment strategy such as rolling, blue/green, or canary, and a fast rollback path.
- Monitoring. The team must see a bad release quickly, ideally through automatic health checks that stop or reverse the rollout.
- Decoupled release from deploy. Feature flags let unfinished code reach production switched off.
Common errors
- Removing approval without improving tests. The pipeline becomes fast, but not safe.
- Deploying from a rebuild. The deploy job must use the artifact the build job tested. Rebuilding can produce a different result.
- Overlapping deployments. Two merges close together can start two deploys at once. Use a concurrency setting so that deploys to one environment run one at a time.
- No automated rollback plan. If recovery needs a meeting, you are not ready.
The workflow below fixes the overlap problem. It queues deploys per environment instead of running them in parallel. Add this block at the top level of the workflow file:
concurrency:
group: production-deploy
cancel-in-progress: falseSetting cancel-in-progress: false lets a running deploy finish rather than being cut off halfway.
Exercise
Your team uses the two-job pipeline above, and production requires a reviewer to approve each deploy. A colleague says that removing the reviewer requirement is all it takes to be ready for continuous deployment. What is missing from that claim, and name two things you would check first?
Show answer
Removing the reviewer only removes the gate. Readiness depends on the safety around it. Check, for example, that the automated tests reliably catch serious failures, that there is a deployment strategy and a fast rollback path, that monitoring or health checks will detect a bad release, and that feature flags or small changes limit the damage of any single release.