CI/CD stands for continuous integration and continuous delivery or continuous deployment. It is the practice of having an automated process – the CI/CD pipeline – build and test every code change and bring it to a release-ready state, or even deploy it, without manual work.
The goal is simple: a release shouldn’t be a dreaded event clicked through by hand, but a boring, repeatable step that can run several times a day.
What does CI (continuous integration) mean?
Continuous integration means that developers merge their work into the shared branch often, even several times a day, and the build and tests run automatically for every such change. If something breaks, it turns up within minutes – while the developer still remembers what they changed – and not weeks later, in a big merge.
CI needs three things:
- version control (Git), in which every change is a commit,
- automated tests, which make it machine-verifiable that the code works,
- a CI server, which runs them on every push.
What does CD mean: delivery or deployment?
“CD” can refer to two closely related things. The difference is in the last step: whether a person starts the production deployment, or it happens by itself.
| Continuous delivery | Continuous deployment | |
|---|---|---|
| What is automated? | Build, tests, releasable package, deployment to a test environment | Everything, including the production deployment |
| Production release | A person starts it, with one click | Happens by itself if all tests are green |
| Who is it for? | Most teams should start with this | Mature teams with strong test coverage |
Continuous delivery alone is a huge step compared with manual releases: the production deployment uses the same automated process as the test one; only the trigger remains a human decision.
What is a CI/CD pipeline?
The pipeline is the sequence of steps that turns a commit into a deployed application. The steps are organised into stages; a stage only starts if the previous one was successful. A typical pipeline:
- Build: installing dependencies, compiling the code or building a container image.
- Test: unit and integration tests, code style checks, static analysis.
- Security checks: looking for vulnerable dependencies and committed passwords.
- Packaging: uploading the releasable artefact (for example a Docker image) to a registry, tagged with the commit ID.
- Deployment to a test environment (staging): automatically, for every change.
- Deployment to production: with one click (delivery) or automatically (deployment).
An important principle is that the same package goes to the test environment and to production. If you rebuild for the production deployment, you are no longer releasing exactly what you tested.
A simple pipeline with GitLab CI
In GitLab CI, the pipeline is described by the .gitlab-ci.yml file in the root of the repo. The example below tests a PHP application, builds a Docker image from it, then deploys it automatically to the test environment, and to production at the press of a button:
stages:
- test
- build
- deploy
test:
stage: test
image: composer:2
script:
- composer install --no-interaction --prefer-dist
- vendor/bin/phpunit
build:
stage: build
image: docker:27
services:
- docker:27-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy_staging:
stage: deploy
script:
- ./deploy.sh staging "$CI_COMMIT_SHORT_SHA"
environment: staging
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
deploy_production:
stage: deploy
script:
- ./deploy.sh production "$CI_COMMIT_SHORT_SHA"
environment: production
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
A few things worth noticing:
- The tests run on every branch, on every push (their result is also visible in the merge request), but the build and the deployment only on the main branch.
- The image tag is the commit’s short ID (
$CI_COMMIT_SHORT_SHA), so you always know exactly which code is running, and a rollback is the deployment of an earlier tag. - The
CI_REGISTRY_*variables are provided by GitLab, so you don’t need to write a password into the repo. deploy.shcontains your own deployment steps: adocker compose pull && docker compose up -dover SSH, a Kubernetes update or a call to a cloud service’s API.- Because of
when: manual, this is continuous delivery: the production deployment is a button in the GitLab interface. If you remove it, it becomes continuous deployment.
GitLab CI, GitHub Actions or Jenkins?
| Tool | Where does the definition live? | Typically suits |
|---|---|---|
| GitLab CI | .gitlab-ci.yml in the repo |
Those whose code is on GitLab (in the cloud or on their own server); built-in registry and environment management |
| GitHub Actions | .github/workflows/*.yml |
For projects hosted on GitHub; a large library of ready-made steps (actions) |
| Jenkins | Jenkinsfile in the repo, plus the Jenkins server’s settings |
Where Jenkins is already in place, or a very custom process connecting many systems is needed |
| AWS CodePipeline | AWS console or infrastructure code | For applications running on AWS, deploying into AWS services |
In most cases the right choice is wherever your code already is: GitLab CI for a GitLab repo, GitHub Actions for a GitHub repo. Running a separate Jenkins server is a job in itself.
When is it worth it for a small team?
Almost always, if any of the following sounds familiar:
- a release is an FTP upload or a series of commands run by hand over SSH,
- only one person knows how to do a release,
- nobody dares to deploy on a Friday,
- “it works on my machine” – just not on the server.
You don’t have to introduce everything at once. A good order:
- Have the tests run automatically on every push (if you don’t have any yet, start with a few critical flows).
- Have the releasable package (image or archive) built in the pipeline, not on a developer’s machine.
- Have every change deployed automatically to the test environment.
- Make the production deployment a single button, with a tested rollback step.
Common mistakes
- Passwords in the repo. Secrets have to be stored in the CI tool’s protected variables (on GitLab as masked and protected variables), never in the code.
- Slow pipeline. If a run takes half an hour, developers work around it. Caching dependencies and parallel jobs help a lot.
- No rollback. If every release gets a unique tag, a rollback is just redeploying an earlier tag.
- Flaky tests. Tests that occasionally fail for no reason teach the team that a red pipeline “doesn’t matter”. These have to be fixed or removed.
- Servers changed by hand. If server settings are changed by hand, after a while the pipeline doesn’t get the environment it expects. The solution is to manage the infrastructure as code too.
Frequently asked questions
Is CI/CD only for big companies? No. It pays off for a two-person team too; in fact that is where the gain is biggest: there is no separate person to deal with releases, so automation directly frees up development time.
Do you need Kubernetes or Docker for it? It isn’t mandatory. A pipeline can also deploy to a traditional server. Containers do simplify a lot, though, because the same image runs in test and in production.
What is the difference between CI/CD and DevOps? DevOps is a broader way of working in which development and operations are jointly responsible for the software; CI/CD is one of its most important tools. More on this: What is DevOps?
How do we do it?
In a recently completed project we moved a PHP application running on cPanel into containers, with a GitLab pipeline, Portainer and Traefik. In Moving a PHP application into containers with a GitOps approach we describe what we built and what we ran into.
If your releases are still manual and you would like to automate them, you can read about how we can help on the Cloud and DevOps page.