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
Docker Build and Push
Multi-Environment Deployment
Set KUBE_CA_CERT_FILE as a GitLab file variable containing the cluster CA certificate,
and provide KUBE_TOKEN through a protected, masked CI variable. The file variable
contains a path that kubectl uses to verify the API server certificate. Protect both
develop and main so the deployment jobs can read the protected token.
Terraform Pipeline
Security Scanning
Caching Strategies
Dynamic Child Pipelines
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


