#GitLab CI
Built-in CI/CD for GitLab repositories.
#Basic Pipeline
yaml
1# .gitlab-ci.yml
2stages:
3 - build
4 - test
5 - deploy
6
7variables:
8 NODE_VERSION: "20"
9
10build:
11 stage: build
12 image: node:${NODE_VERSION}
13 script:
14 - npm ci
15 - npm run build
16 artifacts:
17 paths:
18 - dist/
19 expire_in: 1 hour
20
21test:
22 stage: test
23 image: node:${NODE_VERSION}
24 script:
25 - npm ci
26 - npm test
27 coverage: '/Coverage: \d+\.\d+%/'
28
29deploy:
30 stage: deploy
31 script:
32 - echo "Deploying..."
33 environment:
34 name: production
35 url: https://example.com
36 only:
37 - main
38 when: manual#Docker Build
yaml
1build-image:
2 stage: build
3 image: docker:latest
4 services:
5 - docker:dind
6 variables:
7 DOCKER_TLS_CERTDIR: "/certs"
8 script:
9 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
10 - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
11 - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA#Key Features
| Feature | Description |
|---|---|
| Auto DevOps | Automatic CI/CD |
| Container Registry | Built-in |
| Environments | Track deployments |
| Review Apps | Preview environments |
| Security scanning | SAST, DAST |
[!TIP] Pro Tip: GitLab CI is powerful for self-hosted and enterprise!