Your first CI/CD pipeline: what actually belongs in step one

Your first CI/CD pipeline doesn't need to do everything. It needs to do three things reliably: build, test, deploy. Everything else can be added later.

Three stages are enough to start

A test stage, a build stage, and a deploy stage cover most projects at the start. Extra stages like security scans or performance tests can simply be added once the basic structure is in place.

.gitlab-ci.yml
stages:
  - test
  - build
  - deploy

test:
  stage: test
  script:
    - npm ci
    - npm test

build:
  stage: build
  script:
    - docker build -t registry.example.com/app:$CI_COMMIT_SHA .
    - docker push registry.example.com/app:$CI_COMMIT_SHA

deploy:
  stage: deploy
  script:
    - ./deploy.sh $CI_COMMIT_SHA
  only:
    - main

What belongs in the first step

The tests that already run locally should go into the pipeline first. A build step that produces a container image and tags it with the commit hash instead of latest makes every release clearly traceable.

Automate deployment only once tests are solid

Automated deployment without reliable tests just moves the risk further down the line. It pays to build a solid test stage first and automate deployment afterwards, perhaps initially only to a staging environment.

When more effort pays off

Once several teams work on the same pipeline or compliance requirements come into play, extra stages like security scans, load tests, or a manual approval step before production start to pay off.

Back to the blog

Have a software project?

Describe in a few sentences what you need. We'll reply with questions or a suggestion for the next step.

Get in touch