Overview
Provides a systematic 5-step workflow to diagnose and fix slow, flaky, or costly CI/CD pipelines. Covers bottleneck identification, parallelization, smart test selection, caching hierarchy, artifact reuse, flaky test quarantine, and cost optimization techniques with concrete before/after metrics and GitHub Actions examples.
When to Use This Skill
- Pipelines take too long (developers are waiting).
- High flakiness rate.
- CI costs are rising.
- User says "make the build faster" or "fix flaky tests".
Prerequisites
- Existing CI configuration (GitHub Actions, GitLab CI, etc.).
- Access to CI logs, timing data, and cost reports.
- Test suite that can be run locally for experimentation.
Steps
Measure current state:
- Record wall time for full pipeline on main.
- Identify the slowest job(s) from timing graphs.
- Count flaky test rate (retries needed).
Parallelize:
- Split large jobs (e.g., test into shard by file or by package).
- Use matrix strategy.
- Run independent jobs in parallel (
needs: only where required).
Caching hierarchy (most impactful):
- Dependencies (node_modules, pip cache, Go modules).
- Build cache (Next.js, Turborepo, Gradle, etc.).
- Docker layer cache.
- Test results / coverage cache.
Smart test selection:
- Changed-files detection (only run tests for packages that changed).
- Use tools like
nx affected, Turborepo, or custom scripts.
- Quarantine known flaky tests into a separate "flaky" job that runs less often.
Artifact & reuse:
- Upload build artifacts from build job and download in deploy/test jobs instead of rebuilding.
- Use
actions/cache or native cache features.
Cost optimization:
- Use larger runners only when needed.
- Cancel in-progress workflows on new pushes to same branch.
- Self-hosted runners for high-volume repos.
Output:
- Diagnosis report template.
- Optimized workflow diff.
- Flaky test handling pattern.
- Before/after timing expectations.
Examples
A before/after GitHub Actions workflow showing parallel test sharding, aggressive caching, affected tests only, and cancellation is included, along with a flaky test quarantine pattern.
Edge Cases & Error Handling
- Monorepos: Use workspace-aware tools (Nx, Turborepo, pnpm workspaces).
- Flaky tests that are actually bugs: Quarantine + create ticket, do not ignore.
- Cache invalidation bugs: Provide cache key best practices (hash of lockfile + OS).
Verification
- Re-run the pipeline multiple times and record new average duration.
- Flaky test rate drops (tracked in CI logs or a dashboard).
- Cost report shows reduction (if applicable).
- Developers report faster feedback on PRs.
- Success: Pipeline is 30-70% faster, reliable, and cheaper while maintaining the same quality gates.
References
1---2name: ci-cd-optimizer3description: Analyzes and optimizes CI/CD pipeline speed, reliability, and cost. Use when pipelines are slow, flaky, or expensive.4license: Apache-2.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: devops10 tags: ci-cd, optimization, caching, flaky-tests, parallelization, cost11---1213## Overview1415Provides a systematic 5-step workflow to diagnose and fix slow, flaky, or costly CI/CD pipelines. Covers bottleneck identification, parallelization, smart test selection, caching hierarchy, artifact reuse, flaky test quarantine, and cost optimization techniques with concrete before/after metrics and GitHub Actions examples.1617## When to Use This Skill1819- Pipelines take too long (developers are waiting).20- High flakiness rate.21- CI costs are rising.22- User says "make the build faster" or "fix flaky tests".2324## Prerequisites2526- Existing CI configuration (GitHub Actions, GitLab CI, etc.).27- Access to CI logs, timing data, and cost reports.28- Test suite that can be run locally for experimentation.2930## Steps31321. **Measure current state**:33 - Record wall time for full pipeline on main.34 - Identify the slowest job(s) from timing graphs.35 - Count flaky test rate (retries needed).36372. **Parallelize**:38 - Split large jobs (e.g., test into shard by file or by package).39 - Use matrix strategy.40 - Run independent jobs in parallel (`needs:` only where required).41423. **Caching hierarchy** (most impactful):43 - Dependencies (node_modules, pip cache, Go modules).44 - Build cache (Next.js, Turborepo, Gradle, etc.).45 - Docker layer cache.46 - Test results / coverage cache.47484. **Smart test selection**:49 - Changed-files detection (only run tests for packages that changed).50 - Use tools like `nx affected`, Turborepo, or custom scripts.51 - Quarantine known flaky tests into a separate "flaky" job that runs less often.52535. **Artifact & reuse**:54 - Upload build artifacts from build job and download in deploy/test jobs instead of rebuilding.55 - Use `actions/cache` or native cache features.56576. **Cost optimization**:58 - Use larger runners only when needed.59 - Cancel in-progress workflows on new pushes to same branch.60 - Self-hosted runners for high-volume repos.61627. **Output**:63 - Diagnosis report template.64 - Optimized workflow diff.65 - Flaky test handling pattern.66 - Before/after timing expectations.6768## Examples6970A before/after GitHub Actions workflow showing parallel test sharding, aggressive caching, affected tests only, and cancellation is included, along with a flaky test quarantine pattern.7172## Edge Cases & Error Handling7374- **Monorepos**: Use workspace-aware tools (Nx, Turborepo, pnpm workspaces).75- **Flaky tests that are actually bugs**: Quarantine + create ticket, do not ignore.76- **Cache invalidation bugs**: Provide cache key best practices (hash of lockfile + OS).7778## Verification79801. Re-run the pipeline multiple times and record new average duration.812. Flaky test rate drops (tracked in CI logs or a dashboard).823. Cost report shows reduction (if applicable).834. Developers report faster feedback on PRs.845. Success: Pipeline is 30-70% faster, reliable, and cheaper while maintaining the same quality gates.8586## References8788- [GitHub Actions Caching](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows)89- [Turborepo Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)90- [Nx Affected](https://nx.dev/nx/affected)91- [Flaky Test Management](https://testing.googleblog.com/2021/04/flaky-tests-10-years-later.html)