Skip to main content

README

GitLab CI/CD Cost Optimization

Complete guide to reducing GitLab compute minute consumption across 70+ projects.


Documentation

Core Guides

  1. Overview - Start here

    • Understanding compute minutes
    • Cost factors and calculations
    • Where costs hide
    • Quick wins checklist
  2. Tracking - Monitoring usage

    • View minute usage (namespace, project, pipeline, job)
    • Historical tracking
    • Setting up alerts
    • API usage and automation
  3. Strategies - Reduce costs

    • Eliminate unnecessary pipelines
    • Auto-cancel redundant jobs
    • Skip jobs when files unchanged
    • Fail fast patterns
    • Resource class selection
    • Self-hosted runners
  4. 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
  5. Pipeline Optimization - Efficient pipelines

    • Rules vs only/except
    • Interruptible jobs
    • Fail fast patterns
    • Timeout and retry strategies
    • Merge request pipelines
    • Parallel execution
  6. 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
  7. Monitoring - Track impact

    • Key metrics to track
    • Automated dashboards
    • Cost attribution reports
    • Alerting and notifications
    • Continuous improvement
  8. 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:

  1. Test locally: npm run lint && npm test
  2. Use Draft MRs for work-in-progress
  3. Validate .gitlab-ci.yml if changed

Read:

For New Projects

Setup checklist:

  1. Use proven .gitlab-ci.yml template
  2. Configure caching with file-based keys
  3. Enable workflow auto-cancel
  4. Set job timeouts
  5. Install pre-commit hooks

Read:

For Project Maintainers

Weekly review:

  1. Check project CI minute usage
  2. Review pipeline duration trends
  3. Identify optimization opportunities
  4. Update team on findings

Read:

For Platform Teams

Monthly tasks:

  1. Review namespace usage
  2. Identify top 10 projects by usage
  3. Calculate cost trends
  4. 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

OptimizationPotential SavingsImplementation Time
Auto-cancel redundant pipelines20-40%5 minutes
Aggressive caching30-50% job time30 minutes
Skip unchanged file jobs15-25%15 minutes
Fail fast patterns10-20%20 minutes
Docker layer caching40-60% build time30 minutes
Self-hosted runnersUp to 100% (moved jobs)Varies
Pre-push validationPrevent 60-80% failures1 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:

MetricTargetGoodNeeds Work
Monthly compute minutesDecreasing<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 deployDecreasing<20 min>40 min

Tools

Required

  • glab - GitLab CLI tool for API access
  • mlr (Miller) - Data processing for reports
  • 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

Case Studies


Contributing

Found an optimization?

  1. Test in your project
  2. Document results (before/after metrics)
  3. Share in team meeting
  4. Update this documentation
  5. 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

  1. Read Overview
  2. Set up Pre-Push Validation
  3. Review Checklist - Daily Developer

Project Maintainer Training

  1. Complete developer training
  2. Read Tracking
  3. Read Strategies
  4. Review Checklist - Weekly Maintenance

Platform Team Training

  1. Complete maintainer training
  2. Read Monitoring
  3. Deep dive Caching
  4. Deep dive Pipeline Optimization
  5. 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:

  1. Eliminate waste - Auto-cancel, skip unnecessary jobs
  2. Speed up execution - Caching, parallelization
  3. Smart resources - Right-sized runners, self-hosted
  4. 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:

  1. Read Overview
  2. Implement Quick Wins
  3. Use Checklist daily
  4. Track with Monitoring

Last Updated: January 2026 Maintained By: Platform Engineering Team Version: 1.0