README
GitLab CI/CD Cost Optimization
Complete guide to reducing GitLab compute minute consumption across 70+ projects.
Documentation
Core Guides
-
Overview - Start here
- Understanding compute minutes
- Cost factors and calculations
- Where costs hide
- Quick wins checklist
-
Tracking - Monitoring usage
- View minute usage (namespace, project, pipeline, job)
- Historical tracking
- Setting up alerts
- API usage and automation
-
Strategies - Reduce costs
- Eliminate unnecessary pipelines
- Auto-cancel redundant jobs
- Skip jobs when files unchanged
- Fail fast patterns
- Resource class selection
- Self-hosted runners
-
Caching Deep Dive - Master caching
- Cache keys and strategies
- Cache scope and policies
- Fallback chains
- Language-specific caching (npm, pip, poetry, etc)
- Docker layer caching
- Troubleshooting
-
Pipeline Optimization - Efficient pipelines
- Rules vs only/except
- Interruptible jobs
- Fail fast patterns
- Timeout and retry strategies
- Merge request pipelines
- Parallel execution
-
Pre-Push Validation - Test locally
- Local GitLab CI testing (gitlab-ci-local)
- Pre-commit hooks (Husky, pre-commit framework)
- GitLab CI YAML validation
- IDE integration
- Docker compose for dependencies
-
Monitoring - Track impact
- Key metrics to track
- Automated dashboards
- Cost attribution reports
- Alerting and notifications
- Continuous improvement
-
Checklist - Quick reference
- Daily developer checklist
- Code review checklist
- New project setup
- Weekly/monthly/quarterly tasks
- Quick wins (30 minutes)
Quick Start
For Developers
Before every push:
- Test locally:
npm run lint && npm test - Use Draft MRs for work-in-progress
- Validate .gitlab-ci.yml if changed
Read:
For New Projects
Setup checklist:
- Use proven .gitlab-ci.yml template
- Configure caching with file-based keys
- Enable workflow auto-cancel
- Set job timeouts
- Install pre-commit hooks
Read:
For Project Maintainers
Weekly review:
- Check project CI minute usage
- Review pipeline duration trends
- Identify optimization opportunities
- Update team on findings
Read:
For Platform Teams
Monthly tasks:
- Review namespace usage
- Identify top 10 projects by usage
- Calculate cost trends
- Share metrics with teams
Read:
Quick Wins
Implement these for immediate impact:
1. Enable Auto-Cancel (5 minutes)
workflow: auto_cancel: on_new_commit: interruptible
Savings: 20-40%
2. Add File-Based Cache Keys (10 minutes)
cache: key: files: - package-lock.json paths: - node_modules/
Savings: 30-50% faster jobs
3. Skip Draft MR Pipelines (5 minutes)
workflow: rules: - if: $CI_MERGE_REQUEST_TITLE =~ /^Draft:/ when: never
Savings: 10-20%
4. Mark Jobs Interruptible (5 minutes)
default: interruptible: true
Impact: Enables auto-cancel
5. Set Aggressive Timeouts (5 minutes)
default: timeout: 15m
Impact: Catch hung jobs faster
Total time: 30 minutes Expected savings: 40-60%
Expected Savings
| Optimization | Potential Savings | Implementation Time |
|---|---|---|
| Auto-cancel redundant pipelines | 20-40% | 5 minutes |
| Aggressive caching | 30-50% job time | 30 minutes |
| Skip unchanged file jobs | 15-25% | 15 minutes |
| Fail fast patterns | 10-20% | 20 minutes |
| Docker layer caching | 40-60% build time | 30 minutes |
| Self-hosted runners | Up to 100% (moved jobs) | Varies |
| Pre-push validation | Prevent 60-80% failures | 1 hour setup |
Combined impact: 60-70% total cost reduction achievable
Optimization Maturity Levels
Level 0: Unoptimized
- No caching
- No timeouts
- All jobs run for all changes
- Baseline cost
Level 1: Basic (20-30% savings)
- Caching configured
- Jobs interruptible
- Workflow rules
Level 2: Intermediate (40-50% savings)
- File-based cache keys
- Jobs skip when files unchanged
- Auto-cancel enabled
- Timeouts configured
Level 3: Advanced (60-70% savings)
- Docker layer caching
- Self-hosted runners
- Pre-push validation
- Component reuse
- Monitoring/alerting
Level 4: Expert (70-85% savings)
- All Level 3 optimizations
- Custom runner infrastructure
- Continuous optimization
- Team-wide adoption
Success Metrics
Track these to measure improvement:
| Metric | Target | Good | Needs Work |
|---|---|---|---|
| Monthly compute minutes | Decreasing | <70% quota | >90% quota |
| Pipeline failure rate | <10% | <5% | >15% |
| Cache hit rate | >80% | >90% | <70% |
| Average pipeline duration | <15 min | <10 min | >20 min |
| Cost per deploy | Decreasing | <20 min | >40 min |
Tools
Required
- glab - GitLab CLI tool for API access
- mlr (Miller) - Data processing for reports
Recommended
- gitlab-ci-local - Test pipelines locally
- husky + lint-staged - Pre-commit hooks
- pre-commit - Pre-commit framework
- Docker - For local testing
Optional
- Prometheus + Grafana - Advanced monitoring
- Datadog - CI/CD monitoring integration
Additional Resources
GitLab Official Docs
Community Resources
- GitLab CI Optimization: 15+ Tips
- Visual Guide to GitLab CI Caching
- Extract Greater Efficiency from CI Pipelines
Case Studies
Contributing
Found an optimization?
- Test in your project
- Document results (before/after metrics)
- Share in team meeting
- Update this documentation
- Create reusable component
Have questions?
- Ask in #ci-cd Slack channel
- Create issue in gitlab-components project
- Email: devops@example.com
Maintenance Schedule
Daily
- Developers use pre-push validation
- Check for pipeline failures
Weekly
- Review project usage trends
- Identify optimization opportunities
- Update team on metrics
Monthly
- Analyze namespace-wide usage
- Generate cost reports
- Share best practices
Quarterly
- Deep dive on top projects
- Implement major optimizations
- Update documentation
- Conduct training
Training
New Developer Onboarding
- Read Overview
- Set up Pre-Push Validation
- Review Checklist - Daily Developer
Project Maintainer Training
- Complete developer training
- Read Tracking
- Read Strategies
- Review Checklist - Weekly Maintenance
Platform Team Training
- Complete maintainer training
- Read Monitoring
- Deep dive Caching
- Deep dive Pipeline Optimization
- Review Checklist - Monthly Organization-Wide
Troubleshooting
High Usage Alert
Pipeline Too Slow
Cache Not Working
Jobs Failing Often
Summary
The Problem: 70+ projects burning through CI minutes at $10/1,000 minutes.
The Solution: Comprehensive cost optimization across:
- Eliminate waste - Auto-cancel, skip unnecessary jobs
- Speed up execution - Caching, parallelization
- Smart resources - Right-sized runners, self-hosted
- Prevent waste - Pre-push validation
Expected Results:
- 60-70% cost reduction
- Faster pipelines (40-60% duration improvement)
- Better developer experience
- Sustainable CI/CD practices
Start Here:
- Read Overview
- Implement Quick Wins
- Use Checklist daily
- Track with Monitoring
Last Updated: January 2026 Maintained By: Platform Engineering Team Version: 1.0