Skills · Infrastructure & ops

Gitlab Ci Patterns

Unverified30/40

Build GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation. Use when implementing GitLab CI/CD, optimizing pipeline performance, or setting up automated testing and deployment.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add gitlab-ci-patterns

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

Build GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation. Use when implementing GitLab CI/CD, optimizing pipeline performance, or setting up automated testing and deployment.

The whole source

No sign-in, no blur, nothing truncated
gitlab-ci-patterns/SKILL.md268 lines5.3 KBRawView on GitHub
Frontmatter — 2 properties
namegitlab-ci-patterns
descriptionBuild GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation. Use when implementing GitLab CI/CD, optimizing pipeline performance, or setting up automated testing and deployment.
1---
2name: gitlab-ci-patterns
3description: Build GitLab CI/CD pipelines with multi-stage workflows, caching, and distributed runners for scalable automation. Use when implementing GitLab CI/CD, optimizing pipeline performance, or setting up automated testing and deployment.
4---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# GitLab CI Patterns
7 
8Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment.
9 
10## Purpose
11 
12Create efficient GitLab CI pipelines with proper stage organization, caching, and deployment strategies.
13 
14## When to Use
15 
16- Automate GitLab-based CI/CD
17- Implement multi-stage pipelines
18- Configure GitLab Runners
19- Deploy to Kubernetes from GitLab
20- Implement GitOps workflows
21 
22## Basic Pipeline Structure
23 
24```yaml
25stages:
26 - build
27 - test
28 - deploy
29 
30variables:
31 DOCKER_DRIVER: overlay2
32 DOCKER_TLS_CERTDIR: "/certs"
33 
34build:
35 stage: build
36 image: node:20
37 script:
38 - npm ci
39 - npm run build
40 artifacts:
41 paths:
42 - dist/
43 expire_in: 1 hour
44 cache:
45 key: ${CI_COMMIT_REF_SLUG}
46 paths:
47 - node_modules/
48 
49test:
50 stage: test
51 image: node:20
52 script:
53 - npm ci
54 - npm run lint
55 - npm test
56 coverage: '/Lines\s*:\s*(\d+\.\d+)%/'
57 artifacts:
58 reports:
59 coverage_report:
60 coverage_format: cobertura
61 path: coverage/cobertura-coverage.xml
62 
63deploy:
64 stage: deploy
65 image: bitnami/kubectl:1.31
66 script:
67 - kubectl apply -f k8s/
68 - kubectl rollout status deployment/my-app
69 only:
70 - main
71 environment:
72 name: production
73 url: https://app.example.com
74```
75 
76## Docker Build and Push
77 
78```yaml
79build-docker:
80 stage: build
81 image: docker:24
82 services:
83 - docker:24-dind
84 before_script:
85 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
86 script:
87 - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
88 - docker build -t $CI_REGISTRY_IMAGE:latest .
89 - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
90 - docker push $CI_REGISTRY_IMAGE:latest
91 only:
92 - main
93 - tags
94```
95 
96## Multi-Environment Deployment
97 
98```yaml
99.deploy_template: &deploy_template
100 image: bitnami/kubectl:1.31
101 before_script:
102 - kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true
103 - kubectl config set-credentials admin --token="$KUBE_TOKEN"
104 - kubectl config set-context default --cluster=k8s --user=admin
105 - kubectl config use-context default
106 
107deploy:staging:
108 <<: *deploy_template
109 stage: deploy
110 script:
111 - kubectl apply -f k8s/ -n staging
112 - kubectl rollout status deployment/my-app -n staging
113 environment:
114 name: staging
115 url: https://staging.example.com
116 only:
117 - develop
118 
119deploy:production:
120 <<: *deploy_template
121 stage: deploy
122 script:
123 - kubectl apply -f k8s/ -n production
124 - kubectl rollout status deployment/my-app -n production
125 environment:
126 name: production
127 url: https://app.example.com
128 when: manual
129 only:
130 - main
131```
132 
133## Terraform Pipeline
134 
135```yaml
136stages:
137 - validate
138 - plan
139 - apply
140 
141variables:
142 TF_ROOT: ${CI_PROJECT_DIR}/terraform
143 TF_VERSION: "1.6.0"
144 
145before_script:
146 - cd ${TF_ROOT}
147 - terraform --version
148 
149validate:
150 stage: validate
151 image: hashicorp/terraform:${TF_VERSION}
152 script:
153 - terraform init -backend=false
154 - terraform validate
155 - terraform fmt -check
156 
157plan:
158 stage: plan
159 image: hashicorp/terraform:${TF_VERSION}
160 script:
161 - terraform init
162 - terraform plan -out=tfplan
163 artifacts:
164 paths:
165 - ${TF_ROOT}/tfplan
166 expire_in: 1 day
167 
168apply:
169 stage: apply
170 image: hashicorp/terraform:${TF_VERSION}
171 script:
172 - terraform init
173 - terraform apply -auto-approve tfplan
174 dependencies:
175 - plan
176 when: manual
177 only:
178 - main
179```
180 
181## Security Scanning
182 
183```yaml
184include:
185 - template: Security/SAST.gitlab-ci.yml
186 - template: Security/Dependency-Scanning.gitlab-ci.yml
187 - template: Security/Container-Scanning.gitlab-ci.yml
188 
189trivy-scan:
190 stage: test
191 image: aquasec/trivy:0.58.0
192 script:
193 - trivy image --exit-code 1 --severity HIGH,CRITICAL $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
194 allow_failure: true
195```
196 
197## Caching Strategies
198 
199```yaml
200# Cache node_modules
201build:
202 cache:
203 key: ${CI_COMMIT_REF_SLUG}
204 paths:
205 - node_modules/
206 policy: pull-push
207 
208# Global cache
209cache:
210 key: ${CI_COMMIT_REF_SLUG}
211 paths:
212 - .cache/
213 - vendor/
214 
215# Separate cache per job
216job1:
217 cache:
218 key: job1-cache
219 paths:
220 - build/
221 
222job2:
223 cache:
224 key: job2-cache
225 paths:
226 - dist/
227```
228 
229## Dynamic Child Pipelines
230 
231```yaml
232generate-pipeline:
233 stage: build
234 script:
235 - python generate_pipeline.py > child-pipeline.yml
236 artifacts:
237 paths:
238 - child-pipeline.yml
239 
240trigger-child:
241 stage: deploy
242 trigger:
243 include:
244 - artifact: child-pipeline.yml
245 job: generate-pipeline
246 strategy: depend
247```
248 
249 
250## Best Practices
251 
2521. **Use specific image tags** (node:20, not node:latest)
2532. **Cache dependencies** appropriately
2543. **Use artifacts** for build outputs
2554. **Implement manual gates** for production
2565. **Use environments** for deployment tracking
2576. **Enable merge request pipelines**
2587. **Use pipeline schedules** for recurring jobs
2598. **Implement security scanning**
2609. **Use CI/CD variables** for secrets
26110. **Monitor pipeline performance**
262 
263## Related Skills
264 
265- `github-actions-templates` - For GitHub Actions
266- `deployment-pipeline-design` - For architecture
267- `secrets-management` - For secrets handling
268 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Infrastructure & ops