How do I set up a CI/CD pipeline?

Updated October 2026 · How we answer

Short answerChoose a CI/CD tool (GitHub Actions, GitLab CI, Jenkins), define stages (build, test, deploy) in a config file, connect your repo, and add deployment steps with secrets. Start simple and iterate.

Step-by-step setup

First, pick a tool that fits your repo host. GitHub Actions works natively with GitHub; GitLab CI with GitLab; Jenkins is self-hosted and flexible. Create a configuration file (e.g., `.github/workflows/main.yml` or `.gitlab-ci.yml`) in your repo.

Define stages: build (compile, package), test (unit, integration), and deploy (to staging, then production). Use environment variables or secrets for credentials. For deployment, you can SSH to a server, push to a container registry, or use a cloud provider's CLI.

  • Choose a CI/CD tool and connect your repository.
  • Write a pipeline config file with stages.
  • Add secrets (API keys, SSH keys) in the tool's settings.
  • Run the pipeline on push or pull request.
  • Add manual approval for production if needed.

Example and best practices

A simple GitHub Actions workflow: on push to main, run `npm install`, `npm test`, then `npm run build`, then deploy via `scp` or a cloud CLI. Keep the pipeline fast (under 10 minutes) by caching dependencies and running tests in parallel.

Start with just build and test, then add deployment. Use separate pipelines for staging and production. Monitor pipeline failures and fix them promptly. Store artifacts (build outputs) so you can redeploy without rebuilding.

Common mistakes

  • Hardcoding secrets in the pipeline config instead of using the tool's secret store.
  • Making the pipeline too complex at first; start with build and test, then add deploy.
  • Ignoring pipeline failures, which erodes trust in the process.
From our shopsTitan Case: Premium MagSafe iPhone cases with a precision fit.