Sub topic 9
Continuous delivery: always ready to release
This chapter assumes you know basic Git, can read simple YAML, and have seen a CI workflow that builds and tests code on each push. Here you extend that workflow so every passing commit becomes a release candidate that you can ship at any time.
What continuous delivery means
Continuous integration (CI) answers the question "does this change work with the rest of the code?" Continuous delivery (CD) asks the next question: "can we release this change right now?"
A team practices continuous delivery when every commit that passes the pipeline produces a deployable artifact, and a person can release it with one deliberate action. The release is a business decision, not a technical project. The pipeline has already done the checking.
Continuous delivery does not mean you deploy to production on every commit. That is continuous deployment, covered in the next chapter. The difference is one step: in continuous delivery, a human approves the final deploy.
The pipeline shape
A delivery pipeline builds once, then promotes that same artifact toward production.
Three properties make this work:
- One artifact. The file you test is the file you ship. Rebuilding for production can produce a different result, so you never do it.
- Automated deploys. The deploy step is a script, not a checklist. A script runs the same way every time.
- A gate. The pipeline pauses before production until someone approves.
A two-job pipeline
The following GitHub Actions workflow has a build job and a deploy job. The deploy job waits for build, downloads the same artifact, and runs a deploy script.
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 is what each part does:
needs: buildmakesdeployrun only ifbuildsucceeds.upload-artifactanddownload-artifactpass the builtdist/folder between jobs. Each job runs on a fresh machine, so files do not carry over on their own.environment: productionlinks the job to a GitHub environment. In the repository settings, you can add required reviewers to that environment. The job then pauses until a reviewer approves it. That pause is the manual gate that makes this continuous delivery../scripts/deploy.shis a placeholder for your own deploy script.
What "always ready" requires
A manual gate is only safe if the code behind it is always releasable. That takes several habits:
- Keep
maingreen. If the build breaks, fixing it comes before new work. - Test enough to trust the result. If approvers still run manual checks after the pipeline passes, the pipeline is not yet doing its job.
- Deploy to a production-like staging environment first. Differences between staging and production hide bugs until release day.
- Separate deploying from releasing. Feature flags let you ship unfinished code switched off, so incomplete work never blocks a release.
Common errors
- Rebuilding per environment. This breaks the "same artifact" rule. Build once and promote.
- Approval with no information. A reviewer who can't see what changed or whether staging checks passed will click "approve" without judging anything.
- Long-lived branches. Work that merges rarely is never continuously deliverable. Merge small changes often.
- A deploy script that only works on one person's laptop. Keep it in the repository and run it from the pipeline.
Exercise
A teammate says, "Our pipeline deploys to production automatically after tests pass, and we call that continuous delivery." Which term fits better, and what one change would make it match continuous delivery?
Show answer
It is continuous deployment, because no human approves the production release. Adding a required manual approval (for example, required reviewers on the production environment) before the deploy job would make it continuous delivery.
Exercise
Why does the deploy job download the artifact instead of running npm run build again?
Show answer
The artifact was already tested. Rebuilding could produce a different result, for example from changed dependencies or a different machine, so production could receive something that was never tested. Promoting the same artifact guarantees that what was tested is what ships.