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.
Add this skill
npx mdskills install sickn33/gitlab-ci-patternsComprehensive collection of production-ready GitLab CI patterns with actionable examples across multiple deployment scenarios
1---2name: gitlab-ci-patterns3description: 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---56# GitLab CI Patterns78Comprehensive GitLab CI/CD pipeline patterns for automated testing, building, and deployment.910## Do not use this skill when1112- The task is unrelated to gitlab ci patterns13- You need a different domain or tool outside this scope1415## Instructions1617- Clarify goals, constraints, and required inputs.18- Apply relevant best practices and validate outcomes.19- Provide actionable steps and verification.20- If detailed examples are required, open `resources/implementation-playbook.md`.2122## Purpose2324Create efficient GitLab CI pipelines with proper stage organization, caching, and deployment strategies.2526## Use this skill when2728- Automate GitLab-based CI/CD29- Implement multi-stage pipelines30- Configure GitLab Runners31- Deploy to Kubernetes from GitLab32- Implement GitOps workflows3334## Basic Pipeline Structure3536```yaml37stages:38 - build39 - test40 - deploy4142variables:43 DOCKER_DRIVER: overlay244 DOCKER_TLS_CERTDIR: "/certs"4546build:47 stage: build48 image: node:2049 script:50 - npm ci51 - npm run build52 artifacts:53 paths:54 - dist/55 expire_in: 1 hour56 cache:57 key: ${CI_COMMIT_REF_SLUG}58 paths:59 - node_modules/6061test:62 stage: test63 image: node:2064 script:65 - npm ci66 - npm run lint67 - npm test68 coverage: '/Lines\s*:\s*(\d+\.\d+)%/'69 artifacts:70 reports:71 coverage_report:72 coverage_format: cobertura73 path: coverage/cobertura-coverage.xml7475deploy:76 stage: deploy77 image: bitnami/kubectl:latest78 script:79 - kubectl apply -f k8s/80 - kubectl rollout status deployment/my-app81 only:82 - main83 environment:84 name: production85 url: https://app.example.com86```8788## Docker Build and Push8990```yaml91build-docker:92 stage: build93 image: docker:2494 services:95 - docker:24-dind96 before_script:97 - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY98 script:99 - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .100 - docker build -t $CI_REGISTRY_IMAGE:latest .101 - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA102 - docker push $CI_REGISTRY_IMAGE:latest103 only:104 - main105 - tags106```107108## Multi-Environment Deployment109110```yaml111.deploy_template: &deploy_template112 image: bitnami/kubectl:latest113 before_script:114 - kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true115 - kubectl config set-credentials admin --token="$KUBE_TOKEN"116 - kubectl config set-context default --cluster=k8s --user=admin117 - kubectl config use-context default118119deploy:staging:120 <<: *deploy_template121 stage: deploy122 script:123 - kubectl apply -f k8s/ -n staging124 - kubectl rollout status deployment/my-app -n staging125 environment:126 name: staging127 url: https://staging.example.com128 only:129 - develop130131deploy:production:132 <<: *deploy_template133 stage: deploy134 script:135 - kubectl apply -f k8s/ -n production136 - kubectl rollout status deployment/my-app -n production137 environment:138 name: production139 url: https://app.example.com140 when: manual141 only:142 - main143```144145## Terraform Pipeline146147```yaml148stages:149 - validate150 - plan151 - apply152153variables:154 TF_ROOT: ${CI_PROJECT_DIR}/terraform155 TF_VERSION: "1.6.0"156157before_script:158 - cd ${TF_ROOT}159 - terraform --version160161validate:162 stage: validate163 image: hashicorp/terraform:${TF_VERSION}164 script:165 - terraform init -backend=false166 - terraform validate167 - terraform fmt -check168169plan:170 stage: plan171 image: hashicorp/terraform:${TF_VERSION}172 script:173 - terraform init174 - terraform plan -out=tfplan175 artifacts:176 paths:177 - ${TF_ROOT}/tfplan178 expire_in: 1 day179180apply:181 stage: apply182 image: hashicorp/terraform:${TF_VERSION}183 script:184 - terraform init185 - terraform apply -auto-approve tfplan186 dependencies:187 - plan188 when: manual189 only:190 - main191```192193## Security Scanning194195```yaml196include:197 - template: Security/SAST.gitlab-ci.yml198 - template: Security/Dependency-Scanning.gitlab-ci.yml199 - template: Security/Container-Scanning.gitlab-ci.yml200201trivy-scan:202 stage: test203 image: aquasec/trivy:latest204 script:205 - trivy image --exit-code 1 --severity HIGH,CRITICAL $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA206 allow_failure: true207```208209## Caching Strategies210211```yaml212# Cache node_modules213build:214 cache:215 key: ${CI_COMMIT_REF_SLUG}216 paths:217 - node_modules/218 policy: pull-push219220# Global cache221cache:222 key: ${CI_COMMIT_REF_SLUG}223 paths:224 - .cache/225 - vendor/226227# Separate cache per job228job1:229 cache:230 key: job1-cache231 paths:232 - build/233234job2:235 cache:236 key: job2-cache237 paths:238 - dist/239```240241## Dynamic Child Pipelines242243```yaml244generate-pipeline:245 stage: build246 script:247 - python generate_pipeline.py > child-pipeline.yml248 artifacts:249 paths:250 - child-pipeline.yml251252trigger-child:253 stage: deploy254 trigger:255 include:256 - artifact: child-pipeline.yml257 job: generate-pipeline258 strategy: depend259```260261## Reference Files262263- `assets/gitlab-ci.yml.template` - Complete pipeline template264- `references/pipeline-stages.md` - Stage organization patterns265266## Best Practices2672681. **Use specific image tags** (node:20, not node:latest)2692. **Cache dependencies** appropriately2703. **Use artifacts** for build outputs2714. **Implement manual gates** for production2725. **Use environments** for deployment tracking2736. **Enable merge request pipelines**2747. **Use pipeline schedules** for recurring jobs2758. **Implement security scanning**2769. **Use CI/CD variables** for secrets27710. **Monitor pipeline performance**278279## Related Skills280281- `github-actions-templates` - For GitHub Actions282- `deployment-pipeline-design` - For architecture283- `secrets-management` - For secrets handling284
Full transparency — inspect the skill content before installing.