Build GitLab CI/CD pipelines with multi-stage workflows
Gitlab ci patterns

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 Code
npx skills add wshobson/agents --skill gitlab-ci-patterns -g -a claude-codeClaude 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-patternsWindows (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" -ForceClaude.ai / desktop
Codex, Cursor, other agents
Connects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md5.3 KB
Read the files here
wshobson/
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
- Use specific image tags (node:20, not node:latest)
- Cache dependencies appropriately
- Use artifacts for build outputs
- Implement manual gates for production
- Use environments for deployment tracking
- Enable merge request pipelines
- Use pipeline schedules for recurring jobs
- Implement security scanning
- Use CI/CD variables for secrets
- Monitor pipeline performance
Related Skills
github-actions-templates- For GitHub Actionsdeployment-pipeline-design- For architecturesecrets-management- For secrets handling
| 1 | |
| 2 | name gitlab-ci-patterns |
| 3 | 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. |
| 4 | |
| 5 | |
| 6 | # GitLab CI Patterns |
| 7 | |
| 8 | Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment. |
| 9 | |
| 10 | ## Purpose |
| 11 | |
| 12 | Create 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 | |
| 25 | stages: |
| 26 | - build |
| 27 | - test |
| 28 | - deploy |
| 29 | |
| 30 | variables: |
| 31 | DOCKER_DRIVER: overlay2 |
| 32 | DOCKER_TLS_CERTDIR: "/certs" |
| 33 | |
| 34 | build: |
| 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 | |
| 49 | test: |
| 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 | |
| 63 | deploy: |
| 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 | |
| 79 | build-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 | |
| 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 | |
| 107 | deploy: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 | |
| 119 | deploy: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 | |
| 136 | stages: |
| 137 | - validate |
| 138 | - plan |
| 139 | - apply |
| 140 | |
| 141 | variables: |
| 142 | TF_ROOT: ${CI_PROJECT_DIR}/terraform |
| 143 | TF_VERSION: "1.6.0" |
| 144 | |
| 145 | before_script: |
| 146 | - cd ${TF_ROOT} |
| 147 | - terraform --version |
| 148 | |
| 149 | validate: |
| 150 | stage: validate |
| 151 | image: hashicorp/terraform:${TF_VERSION} |
| 152 | script: |
| 153 | - terraform init -backend=false |
| 154 | - terraform validate |
| 155 | - terraform fmt -check |
| 156 | |
| 157 | plan: |
| 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 | |
| 168 | apply: |
| 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 | |
| 184 | include: |
| 185 | - template: Security/SAST.gitlab-ci.yml |
| 186 | - template: Security/Dependency-Scanning.gitlab-ci.yml |
| 187 | - template: Security/Container-Scanning.gitlab-ci.yml |
| 188 | |
| 189 | trivy-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 | |
| 200 | # Cache node_modules |
| 201 | build: |
| 202 | cache: |
| 203 | key: ${CI_COMMIT_REF_SLUG} |
| 204 | paths: |
| 205 | - node_modules/ |
| 206 | policy: pull-push |
| 207 | |
| 208 | # Global cache |
| 209 | cache: |
| 210 | key: ${CI_COMMIT_REF_SLUG} |
| 211 | paths: |
| 212 | - .cache/ |
| 213 | - vendor/ |
| 214 | |
| 215 | # Separate cache per job |
| 216 | job1: |
| 217 | cache: |
| 218 | key: job1-cache |
| 219 | paths: |
| 220 | - build/ |
| 221 | |
| 222 | job2: |
| 223 | cache: |
| 224 | key: job2-cache |
| 225 | paths: |
| 226 | - dist/ |
| 227 | |
| 228 | |
| 229 | ## Dynamic Child Pipelines |
| 230 | |
| 231 | |
| 232 | generate-pipeline: |
| 233 | stage: build |
| 234 | script: |
| 235 | - python generate_pipeline.py > child-pipeline.yml |
| 236 | artifacts: |
| 237 | paths: |
| 238 | - child-pipeline.yml |
| 239 | |
| 240 | trigger-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 | |
| 252 | **Use specific image tags** (node:20, not node:latest) |
| 253 | **Cache dependencies** appropriately |
| 254 | **Use artifacts** for build outputs |
| 255 | **Implement manual gates** for production |
| 256 | **Use environments** for deployment tracking |
| 257 | **Enable merge request pipelines** |
| 258 | **Use pipeline schedules** for recurring jobs |
| 259 | **Implement security scanning** |
| 260 | **Use CI/CD variables** for secrets |
| 261 | **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 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillAutomates CI/CD pipeline setupCI/CD and Automation
SkillAutomated semantic versioning and release workflowVersion Bump & Release Workflow
SkillOperate Orca-managed worktrees, folder contexts, terminalsOrca CLI
SkillThreaded messages, blocking ask/reply, task dispatchOrca Orchestration
SkillDeploy applications and websites to VercelVercel deploy
SkillOpen or update a pull request on pascalorg/editorOpen PRMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns