Book a free call

How to Set Up CI/CD: A Step-by-Step Guide for Teams

Setting up CI/CD means wiring code to build, test and deploy itself on every change. This guide covers the parts you need and the steps to get a pipeline running.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How to Set Up CI/CD: A Step-by-Step Guide for Teams
On this page

Short answer

Setting up CI/CD means connecting your code repository to an automated pipeline that builds, tests and deploys your software every time someone pushes a change. It replaces manual builds and hand-run deploys with a repeatable process that catches errors early and ships small changes often.

What is CI/CD setup?

CI/CD setup is the work of connecting a code repository to a pipeline that builds, tests and ships software automatically. CI, or continuous integration, means every change is built and tested as soon as it is pushed. CD, or continuous delivery, means the tested change is packaged and made ready to deploy, and continuous deployment goes one step further by releasing it without a manual step.

The setup has four parts: a repository that holds the code, a pipeline file that describes the steps, runners that run those steps, and a deployment target such as a server, a container platform or a cloud service. Most teams start with a hosted CI service, since it provides the runners and the integrations without extra servers to manage.

The goal is a short feedback loop. A developer pushes a change and learns within minutes whether it builds, passes tests and can be released. That loop is what makes small, frequent releases safe.

What do you need before you start?

Before you build a pipeline, you need a working codebase, a test suite that runs without human help, and a place to deploy. A pipeline cannot fix code that does not build or tests that need a person to click through them.

Part What it does Example
Repository Holds code and history GitHub, GitLab, Bitbucket
Pipeline file Describes the steps YAML in the repo
Runners Run the steps Hosted or self-hosted
Tests Check the change Unit and integration tests
Deployment target Runs the software Server or cloud platform

You also need a branching rule the team agrees on. Most small teams use one main branch with short-lived feature branches, and the pipeline runs on every push to a branch and on every merge to main. Keep secrets, such as API keys, in the CI service's secret store rather than in the code. For the background concepts, what is CI/CD explains the terms and the stages in plain language.

How to set up CI/CD in 7 steps

You set up CI/CD by wiring the repository to a pipeline, adding tests, and then adding deployment one step at a time.

  1. Pick a CI service. Choose the one that fits your repository and your stack. Hosted services are the fastest start for most teams.
  2. Add a pipeline file. Create the pipeline file in the repository root and define one job that checks out the code and runs the build.
  3. Add the test step. Run the unit tests in the pipeline and make the job fail when a test fails. A pipeline that passes with broken tests is worse than no pipeline.
  4. Add linting and type checks. Run the linter and any type checker as separate steps so style and type errors are caught with the tests.
  5. Build the release artefact. Add a step that builds the Docker image or the deployable package, and tag it with the commit so every release can be traced.
  6. Deploy to staging first. Send the artefact to a staging environment automatically, and check that the app starts and answers requests before you touch production.
  7. Add production deployment. Add a manual approval or an automatic deploy to production, and keep a rollback step that restores the previous release.

Do the steps in order and check each one works before adding the next. A pipeline that does build and test well is already useful; deployment can follow a week later.

How should the pipeline file be organised?

The pipeline file should be organised into stages that run in order: build, test, then deploy. Each stage holds one or two jobs, and a job fails fast so the team sees the problem in minutes rather than after a long run.

Keep the file short and readable. Put long scripts in separate files in the repository and call them from the pipeline, so the pipeline file reads like a list of steps rather than a wall of commands. Use the same file for every branch, with small changes for staging and production, so a fix in one place helps everywhere.

Cache dependencies between runs so the build does not download the same packages every time. A cached build can cut pipeline time from ten minutes to two, which is the difference between developers waiting and developers moving on. Teams that pair CI with a clear release process also benefit from the practices in what is DevOps, which covers how build, test and release fit together.

Example (hypothetical): a six-person team automates deploys

Example (hypothetical): a team of six developers releases a web app by hand. Each release takes one developer about 45 minutes of building, copying files and checking the server, and the team releases about 40 times a month.

That is 40 times 45 minutes, or 1,800 minutes, which is 30 hours a month spent on manual releases. After setting up CI/CD, the pipeline builds, tests and deploys each change in about 5 minutes of machine time, and the developer only reviews the result.

For the same 40 releases, that is 40 times 5 minutes, or 200 minutes, which is about 3 hours and 20 minutes a month. The team saves roughly 26 hours and 40 minutes a month, and releases stop depending on one person being free to run them.

What are the common mistakes?

The most common mistakes are adding deployment before tests work, keeping secrets in code, and letting the pipeline grow so slow that developers ignore it.

  • Deploying before tests pass. If the pipeline ships code that has not been tested, it automates breakage. Make tests a gate, not a suggestion.
  • Storing secrets in the repository. API keys and passwords belong in the CI secret store. A key committed to the repo should be treated as leaked and rotated at once.
  • One giant pipeline. A single pipeline that does everything takes too long and fails for unclear reasons. Split it into stages and keep each job focused.
  • No rollback plan. A deploy without a tested rollback turns a small bug into a long outage. Practise the rollback before you need it.
  • Ignoring slow pipelines. A pipeline that takes 30 minutes will be skipped or worked around. Cache dependencies and run independent jobs in parallel.

When the pipeline is in place, DevOps services can help a team that wants outside help tuning it. See vendor site for current tool pricing.

How to keep the pipeline fast and safe

You keep a pipeline fast and safe by measuring it, trimming slow steps, and treating the pipeline itself as code that needs review.

Watch two numbers: how long a run takes and how often it fails for reasons that are not real bugs. If runs take longer than ten minutes, cache more and split slow tests into a separate job. If runs fail often for flaky reasons, fix the flaky test or the step that causes it, since a pipeline the team does not trust is a pipeline the team works around.

Review pipeline changes like code changes. A bad pipeline edit can break every deploy, so it deserves the same review and testing as the application code. Keep the pipeline file in the repository so its history is visible and any change can be reverted.

Key takeaways

  • CI/CD setup connects your repository to a pipeline that builds, tests and deploys on every push
  • Start with build and test, then add staging, then production deployment
  • Keep secrets in the CI secret store, never in the repository
  • A pipeline that takes more than ten minutes will be ignored, so cache and split slow jobs
  • Practise the rollback before you need it

Frequently asked questions

How long does it take to set up CI/CD?

A basic pipeline with build and test takes a day for a small codebase with a working test suite. Adding staging and production deployment usually takes another few days, since deployment needs credentials, environments and a rollback plan.

Which CI/CD tool should I choose?

Choose the tool that fits your repository and your stack. GitHub Actions fits GitHub repos, GitLab CI fits GitLab repos, and Jenkins fits teams that need full control. The pipeline habits matter more than the tool, so pick one and learn it well.

Do I need tests before setting up CI/CD?

Yes. A pipeline without tests only automates the build, and it will ship broken code faster. Add unit tests first, make them run without human help, and then wire them into the pipeline as a gate.

What is the difference between continuous delivery and continuous deployment?

Continuous delivery means every tested change is ready to deploy, but a person approves the release. Continuous deployment means the pipeline releases every tested change on its own. Most teams start with delivery and move to deployment once they trust the tests.

How do I deploy safely with CI/CD?

Deploy to staging first, run a smoke test, and then release to a small share of production traffic before going wide. Keep the previous release ready to roll back, and make sure someone is watching the first minutes after each release.

Can I set up CI/CD for a mobile app?

Yes, with extra steps for signing and store review. The pipeline builds the app, runs tests, signs the package with a stored key, and uploads it to the store or to a test group. Store review still takes time, so mobile teams usually deploy to testers automatically and to the store on approval.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: software products in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Setting up your first pipeline?

A senior engineer replies within one business day. Or see our DevOps service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call