Skip to content

Continuous integration and continuous deployment (CI/CD)

Introduction

On every code commit, machines automatically run tests and package the build, then release it automatically if all is well, with no manual steps.

Glossary

  • CI (continuous integration): on every commit, automatically run checks and tests to catch problems early.
  • CD (continuous delivery / continuous deployment): after checks pass, automatically build a releasable artifact and (automatically or with one button) deploy it to an environment.
  • Artifact: the build output, such as a Docker image or an installer. Build once, use everywhere: the artifact validated in test is the same one that goes to production.
  • Pipeline: the config file that chains these steps together, stored in the same repository as the code.

Why use it

  • Catch problems early: bad code is stopped by tests before it is merged.
  • Repeatable: the process is written as a file, so anyone who triggers it gets the same result.
  • Make releases routine: frequent small releases are far less risky than rare big ones.

How to do it

A typical flow, in order; stop on any failure:

  1. Check out the code and install dependencies (use caching to speed this up)
  2. Lint / static analysis
  3. Run tests (see Testing strategy)
  4. Build the artifact (such as a Docker image), tag it with a version (commit SHA or version number—do not use only latest)
  5. Push to the artifact registry
  6. Auto-deploy to the test environment, then deploy to production after smoke tests pass (you can add a manual approval)
  7. Run database migrations automatically on deploy (see Database migrations)

Component comparison

GitHub Actions

Managed serviceFree tier + paidOpsLow

When your code is on GitHub, every commit automatically runs tests, builds, and deploys in the cloud.

Best forIndividuals and small to mid-sized teams whose code is hosted on GitHub.

Avoid whenThe code is not on GitHub, or the network to GitHub is very unstable.

Pros

Seamlessly integrated with GitHub repositories, with configuration as a file in the repo

The community offers a large number of ready-made steps you can reuse directly

No build machines to maintain yourself

Cons

Free build minutes for private repositories are limited, and exceeding them costs money

Server keys must be stored in GitHub, so permissions need careful management

Access to GitHub from China is sometimes unstable, making dependency downloads during builds slow

Official docs ↗

Gitea Actions / Woodpecker (self-hosted)

Self-hosted open sourceOpen sourceOpsMedium

Set up a lightweight code repository (Gitea) on your own server and use Gitea Actions or Woodpecker for automated builds.

Best forSmall teams that want private, self-managed code and have limited server resources.

Avoid whenNobody is willing to maintain these services, or the code is already on GitHub and working well.

Pros

Code and builds are in your own hands, with no dependence on an external platform

Much lighter than GitLab or Jenkins

Gitea Actions syntax is close to GitHub Actions

Cons

You must deploy, upgrade, and back up the code repository and build machines yourself

Fewer community resources and ready-made steps than GitHub Actions

When the build machine itself has problems, nobody backs you up

Official docs ↗

GitLab CI

Managed serviceFree tier + paidOpsMedium

GitLab's built-in automated build feature, usable through the official SaaS or by running your own GitLab.

Best forTeams already using GitLab to manage code.

Avoid whenYou have only a small server but want to self-host, or the code is on another platform.

Pros

Code, issue tracking, builds, and an image registry in one place

Full-featured pipelines, supporting multiple stages and approvals

Can be self-hosted so code never leaves your own data center

Cons

Self-hosted GitLab is resource-hungry; a 2-core 2 GB machine basically cannot run it

The configuration file syntax is extensive and takes time to learn

Free build minutes on the SaaS edition are limited, and exceeding them costs money

Official docs ↗

Jenkins

Self-hosted open sourceOpen sourceOpsHigh

A veteran automated build server that can connect to almost any tool through a large number of plugins.

Best forTeams that already have Jenkins, or scenarios with complex workflows that need heavy customization.

Avoid whenNew projects and small teams, when lighter and easier options exist.

Pros

An enormous number of plugins, so almost any workflow can be built

Fully self-hosted, with no dependence on an external platform

Widely used in enterprises, with plenty of documentation

Cons

You must maintain the server yourself, continuously keeping up with plugin upgrades and security vulnerabilities

The interface and configuration experience feel dated

Running it takes a fair amount of memory

Official docs ↗

Cloud provider pipeline (e.g. Alibaba Cloud Yunxiao)

Cloud-managedFree tier + paidOpsLow

An online pipeline service from a cloud provider; building and deploying to servers on its own cloud is relatively smooth.

Best forChinese teams whose servers are on the same cloud and who want a stable, hassle-free pipeline.

Avoid whenYou want to avoid cloud provider lock-in, or need a large number of ready-made community scripts.

Pros

No build machines to set up, and access within China is stable

Easy to connect with servers, containers, and image registries on the same cloud

Visual configuration interface that is quick to pick up

Cons

Pipeline configuration is tied to the platform and must be rewritten when migrating

Exceeding the free tier or using advanced features may cost money

Fewer community-reusable ready-made steps than GitHub Actions

Using GitHub Actions as an example (place it in .github/workflows/ci.yml):

Checklist

  • Every commit and pull request runs tests automatically
  • Pipeline config lives in the repository
  • Artifacts are built once and reused across environments
  • Secrets use platform encrypted variables; never written into code or logs
  • The main branch is protected: failing tests block merges
  • Deploy is automated and has a clear rollback path