🦊
CI/CD & GitOps

GitLab CI

Built-in CI/CD pipelines for GitLab repositories

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

Alternative — team standard for CI/CD

What is this?

GitLab CI runs automated build and deploy pipelines when you push code to GitLab.

📁

Config files for GitLab CI

Where to create or edit the main configuration — paths below match the setup steps.

  • .gitlab-ci.yml

    Location: Repository root (same level as README)

    Pipeline stages, jobs, and CI/CD rules

📥

Step 01

Set Up GitLab CI

(01)Add .gitlab-ci.yml

No install needed — add pipeline file to your GitLab repo.

Linux
1cat > .gitlab-ci.yml << 'EOF'
2stages: [build, test, deploy]
3build:
4 stage: build
5 script: [npm ci, npm run build]
6test:
7 stage: test
8 script: [npm test]
9EOF
10git add .gitlab-ci.yml && git commit -m "Add CI" && git push
⚙️

Step 02

Configure Pipeline

(01)Docker-based jobs

Linux
1# .gitlab-ci.yml with Docker image:
2# build:
3# image: node:20
4# script: [npm ci, npm run build]
5# artifacts:
6# paths: [dist/]

Step 03

Verify

(01)Check pipeline

Linux
1# GitLab UI → CI/CD → Pipelines

Step 04

Manage

(01)Variables

Linux
1# Settings → CI/CD → Variables
2# Add DOCKER_TOKEN, SSH_KEY, etc.
🔧

Step 05

Common Problems

#1Pipeline stuck or pending

Usually no available runner or runner tags mismatch.

Linux
1# Settings → CI/CD → Runners — need active runner
2# Match tags in .gitlab-ci.yml:
3# tags: [docker]
4# Shared runners must be enabled for the project

#2YAML invalid / pipeline fails to create

Linux
1# Validate locally:
2# CI/CD → Editor → Validate
3# Common fix: indent script: with array [cmd1, cmd2]

📋Config templates

1 YAML template for GitLab CI. Copy and deploy after setup.

1 ready-to-copy template. Expand one, copy the YAML, then run the deploy commands.

.gitlab-ci.yml

yaml
1stages:
2 - build
3 - test
4 - deploy
5
6variables:
7 DOCKER_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
8
9build:
10 stage: build
11 image: docker:24
12 services:
13 - docker:24-dind
14 script:
15 - docker build -t $DOCKER_IMAGE .
16 - docker push $DOCKER_IMAGE
17 only:
18 - main
19
20test:
21 stage: test
22 image: node:20-alpine
23 script:
24 - npm ci
25 - npm test
26
27deploy:
28 stage: deploy
29 image: bitnami/kubectl:latest
30 script:
31 - kubectl set image deployment/myapp app=$DOCKER_IMAGE
32 environment:
33 name: production
34 only:
35 - main
📄

Step 01

Use GitLab CI

(01)Add pipeline to repo

Linux
1git add .gitlab-ci.yml
2git commit -m 'Add GitLab CI pipeline'
3git push