← All insightsAutomation

Automating GitLab CI/CD from scratch

CodeWizard Academy · 29 June 2026 · 3 min read · Intermediate

Anything you do to GitLab CI/CD twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.

1. Install it reproducibly

bash
# Register a self-managed runner (Docker executor)
gitlab-runner register --url https://gitlab.com \
  --registration-token $TOKEN --executor docker --docker-image alpine:3

2. Describe the desired state

Stages, caching and a manual production gate.

yaml
stages: [build, test, deploy]
cache: { paths: [node_modules/] }

build:
  stage: build
  image: node:20
  script: [npm ci, npm run build]

test:
  stage: test
  image: node:20
  script: [npm test]

deploy:prod:
  stage: deploy
  script: [./deploy.sh]
  environment: { name: production }
  when: manual
  rules: [{ if: '$CI_COMMIT_BRANCH == "main"' }]

3. Run it from CI

Reuse shared pipeline logic with include.

yaml
include:
  - project: acme/ci-templates
    file: /templates/node.yml
  - template: Security/SAST.gitlab-ci.yml

Want senior help putting GitLab CI/CD to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult