Build GitLab CI/CD pipelines with multi-stage workflows

Gitlab ci patterns

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Gitlab ci patterns cover

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.

---
name: gitlab-ci-patterns
description: 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.
---

# GitLab CI Patterns

Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment.

## Purpose

Create efficient GitLab CI pipelines with proper stage organization, caching, and deployment strategies.

## When to Use

- Automate GitLab-based CI/CD
- Implement multi-stage pipelines
- Configure GitLab Runners

Overview

Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment.

Manual install (npx, ZIP)
Claude Codenpx skills add wshobson/agents --skill gitlab-ci-patterns -g -a claude-code
Claude Code (manual)mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \ | tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/cicd-automation/skills/gitlab-ci-patterns
Windows (PowerShell)New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/77c67df567156aa99e52/gitlab-ci-patterns.zip" -OutFile "$env:TEMP\gitlab-ci-patterns.zip"; Expand-Archive "$env:TEMP\gitlab-ci-patterns.zip" -DestinationPath "$HOME\.claude\skills" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md5.3 KB
Read the files here
wshobson/4236bb91 file
SKILL.md
Show the full text268 lines

GitLab CI Patterns

Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment.

Purpose

Create efficient GitLab CI pipelines with proper stage organization, caching, and deployment strategies.

When to Use

  • Automate GitLab-based CI/CD
  • Implement multi-stage pipelines
  • Configure GitLab Runners
  • Deploy to Kubernetes from GitLab
  • Implement GitOps workflows

Basic Pipeline Structure

stages:
  - build
  - test
  - deploy

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: "/certs"

build:
  stage: build
  image: node:20
  script:
    - npm ci
    - npm run build
  artifacts:
    paths:
      - dist/
    expire_in: 1 hour
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/

test:
  stage: test
  image: node:20
  script:
    - npm ci
    - npm run lint
    - npm test
  coverage: '/Lines\s*:\s*(\d+\.\d+)%/'
  artifacts:
    reports:
      coverage_report:
        coverage_format: cobertura
        path: coverage/cobertura-coverage.xml

deploy:
  stage: deploy
  image: bitnami/kubectl:1.31
  script:
    - kubectl apply -f k8s/
    - kubectl rollout status deployment/my-app
  only:
    - main
  environment:
    name: production
    url: https://app.example.com

Docker Build and Push

build-docker:
  stage: build
  image: docker:24
  services:
    - docker:24-dind
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
    - docker build -t $CI_REGISTRY_IMAGE:latest .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
    - docker push $CI_REGISTRY_IMAGE:latest
  only:
    - main
    - tags

Multi-Environment Deployment

.deploy_template: &deploy_template
  image: bitnami/kubectl:1.31
  before_script:
    - kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true
    - kubectl config set-credentials admin --token="$KUBE_TOKEN"
    - kubectl config set-context default --cluster=k8s --user=admin
    - kubectl config use-context default

deploy:staging:
  <<: *deploy_template
  stage: deploy
  script:
    - kubectl apply -f k8s/ -n staging
    - kubectl rollout status deployment/my-app -n staging
  environment:
    name: staging
    url: https://staging.example.com
  only:
    - develop

deploy:production:
  <<: *deploy_template
  stage: deploy
  script:
    - kubectl apply -f k8s/ -n production
    - kubectl rollout status deployment/my-app -n production
  environment:
    name: production
    url: https://app.example.com
  when: manual
  only:
    - main

Terraform Pipeline

stages:
  - validate
  - plan
  - apply

variables:
  TF_ROOT: ${CI_PROJECT_DIR}/terraform
  TF_VERSION: "1.6.0"

before_script:
  - cd ${TF_ROOT}
  - terraform --version

validate:
  stage: validate
  image: hashicorp/terraform:${TF_VERSION}
  script:
    - terraform init -backend=false
    - terraform validate
    - terraform fmt -check

plan:
  stage: plan
  image: hashicorp/terraform:${TF_VERSION}
  script:
    - terraform init
    - terraform plan -out=tfplan
  artifacts:
    paths:
      - ${TF_ROOT}/tfplan
    expire_in: 1 day

apply:
  stage: apply
  image: hashicorp/terraform:${TF_VERSION}
  script:
    - terraform init
    - terraform apply -auto-approve tfplan
  dependencies:
    - plan
  when: manual
  only:
    - main

Security Scanning

include:
  - template: Security/SAST.gitlab-ci.yml
  - template: Security/Dependency-Scanning.gitlab-ci.yml
  - template: Security/Container-Scanning.gitlab-ci.yml

trivy-scan:
  stage: test
  image: aquasec/trivy:0.58.0
  script:
    - trivy image --exit-code 1 --severity HIGH,CRITICAL $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
  allow_failure: true

Caching Strategies

# Cache node_modules
build:
  cache:
    key: ${CI_COMMIT_REF_SLUG}
    paths:
      - node_modules/
    policy: pull-push

# Global cache
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .cache/
    - vendor/

# Separate cache per job
job1:
  cache:
    key: job1-cache
    paths:
      - build/

job2:
  cache:
    key: job2-cache
    paths:
      - dist/

Dynamic Child Pipelines

generate-pipeline:
  stage: build
  script:
    - python generate_pipeline.py > child-pipeline.yml
  artifacts:
    paths:
      - child-pipeline.yml

trigger-child:
  stage: deploy
  trigger:
    include:
      - artifact: child-pipeline.yml
        job: generate-pipeline
    strategy: depend

Best Practices

  1. Use specific image tags (node:20, not node:latest)
  2. Cache dependencies appropriately
  3. Use artifacts for build outputs
  4. Implement manual gates for production
  5. Use environments for deployment tracking
  6. Enable merge request pipelines
  7. Use pipeline schedules for recurring jobs
  8. Implement security scanning
  9. Use CI/CD variables for secrets
  10. Monitor pipeline performance
  • github-actions-templates - For GitHub Actions
  • deployment-pipeline-design - For architecture
  • secrets-management - For secrets handling
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---
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 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillAutomates CI/CD pipeline setupCI/CD and Automationaddyosmani/agent-skills · by addyosmaniAutomates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.★ 98.7k GitHub starsSkillAutomated semantic versioning and release workflowVersion Bump & Release Workflowthedotmack/claude-mem · by thedotmackAutomated semantic versioning and release workflow for Claude Code plugins. Handles version increments across package.json, marketplace.json, plugin.json manifests, build verification, git tagging, GitHub releases, and changelog generation. NPM publishing is the final human-required handoff because the maintainer raised npm security.★ 95.6k GitHub starsSkillOperate Orca-managed worktrees, folder contexts, terminalsOrca CLIstablyai/orca · by stablyaiOperate Orca-managed worktrees, folder contexts, terminals, repos, automations, artifacts, skill sharing, worktree comments, and Orca's embedded browser through the `orca` CLI. Use when the user says "$orca-cli", "Orca worktree", "child worktree", "spawn codex/claude in a worktree", "read/wait/send Orca terminal", "handoff" / "handover" / "give this to another agent", "Orca browser", "orca artifacts", or "share skills". Prefer it over raw git worktree, ad hoc PTYs, or Computer Use when Orca state is involved. Use Computer Use only when a visible window needs GUI control that a CLI, filesystem, or API cannot do.★ 84.5k GitHub starsSkillThreaded messages, blocking ask/reply, task dispatchOrca Orchestrationstablyai/orca · by stablyaiCoordinate supervised Orca workers: threaded messages, blocking ask/reply, task dispatch, worker_done/escalation waits, task DAGs, decision gates, coordinator loops, and decomposing work across agents. Use `orca-cli` for full ownership handoffs — "hand off", "handoff", "handover", "give this to another agent", "another worktree" — unless asked to supervise, monitor, or coordinate a DAG, and for terminal control, lightweight terminal prompts, shell commands, Orca worktree management, and reading or waiting on terminals.★ 84.5k GitHub starsSkillDeploy applications and websites to VercelVercel deploybytedance/deer-flow · by bytedanceDeploy applications and websites to Vercel. Use this skill when the user requests deployment actions such as "Deploy my app", "Deploy this to production", "Create a preview deployment", "Deploy and give me the link", or "Push this live". No authentication required - returns preview URL and claimable deployment link.★ 83.5k GitHub starsSkillOpen or update a pull request on pascalorg/editorOpen PRpascalorg/editor · by pascalorgOpen or update a pull request on pascalorg/editor from the current branch, describing only what the branch actually did. Use when the user asks to open/create a PR, push and PR, or ship a branch in the editor repo.★ 24.6k GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars