Sub topic 9
Continuous delivery: always ready to release
This chapter explains what continuous delivery adds on top of continuous integration, how it changes the way a team releases, and how to build it with a two-job pipeline. It assumes you know basic Git (commits, branches, pull requests), can build and test a small application, can use the command line, and can read simple YAML. It also assumes you have met pipelines, jobs, and build artifacts in earlier chapters.
What continuous delivery means
Continuous delivery is the practice of keeping the main branch in a state where it can be released to production at any time, and of making the release itself a routine, automated step. Every change that passes the pipeline produces a release candidate. A release candidate is a specific build artifact that has passed every automated check and could go to production if someone decided to ship it.
The key idea is separating two decisions:
- Is this build good enough to release? The pipeline answers this automatically, using builds, tests, and other checks.
- Should we release it now? A person or a business rule answers this. The reason can be timing, a marketing launch, a support freeze, or a regulatory sign-off.
Continuous integration (CI) stops at "the change merges and the tests pass." Continuous delivery (CD) continues: it packages the change, deploys it to a production-like environment, runs more checks, and leaves a one-step release ready. The release is a button press or an approval, not a project.
What changes compared with manual releases
In a manual process, a release is an event. Someone collects changes, builds on their machine, follows a checklist, and deploys at night. Each step can go wrong, and the more changes bundled together, the harder it is to find the cause of a failure.
Continuous delivery shrinks the release into small, frequent, repeatable steps.
| Aspect | Manual release | Continuous delivery |
|---|---|---|
| Release size | Many changes bundled together | One change or a few |
| Release steps | Checklist followed by a person | Scripted and run by the pipeline |
| Build used in production | Often rebuilt for each target | One artifact, promoted unchanged |
| Cost of a release | High, so releases are rare | Low, so releases are frequent |
| Failure diagnosis | Many suspects | Few suspects |
| Release decision | Entangled with the work of releasing | A separate, explicit choice |
Releasing often is safer than it sounds. A small change is easy to understand, easy to test, and easy to undo.
The delivery pipeline
A delivery pipeline extends the CI pipeline with stages that prepare and deploy the artifact. A typical flow looks like this:
Each stage has a job to do:
- Build and unit tests. Compile or bundle the code and run fast tests. This is the CI part.
- Store the artifact. Save the built output once. Every later stage uses this exact file, so what you tested is what you ship.
- Deploy to staging. Staging is an environment that mimics production. Deploying there proves the deployment process itself works.
- Acceptance and smoke tests. Acceptance tests check that the application does what users need. Smoke tests are a few quick checks that the deployed system starts and its main paths respond.
- Approval gate. A gate is a point where the pipeline pauses until a condition is met. In continuous delivery, the condition is often a human approval.
- Deploy to production. The same artifact, the same deploy script, a different target.
A failure at any stage stops the pipeline, and the candidate never reaches production.
Build once, deploy many times
The most important rule in continuous delivery is to build the artifact once and promote it. Rebuilding for each environment risks shipping something different from what you tested. A different dependency version, a different build tool, or a changed timestamp can all make the production build behave differently from the staging build.
The consequence for configuration is that the artifact must not contain environment-specific values. Settings such as database addresses and API keys come from the environment at deploy time. If you find yourself changing code to deploy to production, the artifact is not truly promotable.
A working example
The following workflow is from the tutorial's plan. It has two jobs. The build job tests the code, builds it, and uploads the output as an artifact. The deploy job runs only after build succeeds, downloads the same artifact, and deploys it.
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/Read it with continuous delivery in mind:
needs: buildmakesdeploywait forbuild. If tests fail, nothing deploys.upload-artifactanddownload-artifactcarry the samedist/folder between the jobs. Nothing is rebuilt.environment: productionties the job to a named environment. In GitHub, you can configure that environment in the repository settings to require a reviewer's approval. The job then pauses before it starts, until an approver accepts it. That pause is the approval gate in the diagram, and it is what makes this pipeline continuous delivery../scripts/deploy.shis a placeholder. You must supply your own script, which copies the files to a server, uploads them to a bucket, or calls your platform's deploy command.
The workflow has only one deployment target. A fuller delivery pipeline would add a staging job between build and deploy, with its own environment: staging, and make the production job depend on it.
Gates and approvals
A gate stops the pipeline until a condition holds. Common gates include:
- Manual approval. A named person or team accepts the release. This suits teams that want a human decision before production.
- Automated quality gate. The pipeline checks a rule, such as "test coverage did not fall" or "no critical vulnerabilities found."
- Time window. Deployments are allowed only at certain times, such as outside a peak sales period.
- Dependency check. Another service must be at a compatible version first.
Keep gates few and meaningful. A gate that is always approved without looking adds delay and no safety.
Database and configuration changes
Application code is the easy part. Database schema changes need extra care, because the old and new versions of the application may run against the same database during a deployment, or you may need to roll back the code while the new schema stays in place.
A common approach is the expand and contract pattern:
- Expand. Add the new column or table in a way the old code ignores. Deploy this change first.
- Migrate. Deploy code that writes to both the old and new structures, and copy existing data across.
- Contract. After all code uses the new structure, remove the old one in a later release.
Each step can be released and rolled back on its own. This keeps every release candidate safe to ship at any time.
Common errors
- Rebuilding per environment. The production artifact differs from the tested one. Fix it by uploading once and downloading in later jobs.
- Configuration baked into the artifact. You must rebuild to change a setting. Move settings into environment variables or a configuration service read at deploy time.
- Staging that differs from production. Tests pass in staging and fail in production. Keep the operating system, runtime versions, and service topology as close as practical.
- A broken main branch left unfixed. If the main branch stays red, nothing is releasable. Treat a failing pipeline on main as the team's first priority.
- Manual steps hidden in the process. A deploy that needs someone to edit a file by hand is not continuous delivery. Script it.
- Slow pipelines. If the pipeline takes hours, people batch changes and the benefits fade. Run quick tests first and run slower ones in parallel.
- Approvals as a rubber stamp. Gates that nobody reviews add delay without adding safety.
Continuous delivery and continuous deployment
Continuous delivery and continuous deployment share the same pipeline. The difference is the last step. In continuous delivery, a person or rule decides when a release candidate goes to production. In continuous deployment, which the next chapter covers, every change that passes all checks goes to production with no human decision. If you remove the approval requirement from the production environment in the example above, you move from delivery to deployment.
You can also use continuous delivery as a stepping stone. Many teams start with manual approval, build trust in their tests, and later remove the gate.
Exercise
In the two-job workflow above, you want to deploy to a staging environment first and only then to production, using the same artifact both times. What change would you make to the workflow?
Show answer
Add a third job, for example deploy-staging, with needs: build and environment: staging. It downloads the dist artifact and runs the deploy script against staging, and ideally runs smoke tests after. Then change the production job to needs: deploy-staging (or needs: [build, deploy-staging]) so it runs only after staging succeeds. Nothing is rebuilt. Every job downloads the dist artifact that the build job uploaded. You can also set a required reviewer on the production environment in the repository settings to add the approval gate.
Exercise
A teammate says, "We have continuous delivery, because we deploy to production every Friday after a developer builds the release on their laptop." Is that continuous delivery? Give two reasons.
Show answer
No. First, the release is built by hand on one person's machine, so it is not an automated, repeatable pipeline, and the artifact can differ from what was tested. Second, releasing on a fixed weekly schedule with bundled changes means the code is not kept in a state where any passing change can be released at any time through an automated process. Continuous delivery needs an automated pipeline that produces a tested artifact on every change and makes release a low-effort, routine decision.