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
Source: Nikoxkx/Agent-Skills — distributed by TomeVault.
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.05---67## Overview89Provides 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.1011## When to Use This Skill1213- Pipelines take too long (developers are waiting).14- High flakiness rate.15- CI costs are rising.16- User says "make the build faster" or "fix flaky tests".1718## Prerequisites1920- Existing CI configuration (GitHub Actions, GitLab CI, etc.).21- Access to CI logs, timing data, and cost reports.22- Test suite that can be run locally for experimentation.2324## Steps25261. **Measure current state**:27 - Record wall time for full pipeline on main.28 - Identify the slowest job(s) from timing graphs.29 - Count flaky test rate (retries needed).30312. **Parallelize**:32 - Split large jobs (e.g., test into shard by file or by package).33 - Use matrix strategy.34 - Run independent jobs in parallel (`needs:` only where required).35363. **Caching hierarchy** (most impactful):37 - Dependencies (node_modules, pip cache, Go modules).38 - Build cache (Next.js, Turborepo, Gradle, etc.).39 - Docker layer cache.40 - Test results / coverage cache.41424. **Smart test selection**:43 - Changed-files detection (only run tests for packages that changed).44 - Use tools like `nx affected`, Turborepo, or custom scripts.45 - Quarantine known flaky tests into a separate "flaky" job that runs less often.46475. **Artifact & reuse**:48 - Upload build artifacts from build job and download in deploy/test jobs instead of rebuilding.49 - Use `actions/cache` or native cache features.50516. **Cost optimization**:52 - Use larger runners only when needed.53 - Cancel in-progress workflows on new pushes to same branch.54 - Self-hosted runners for high-volume repos.55567. **Output**:57 - Diagnosis report template.58 - Optimized workflow diff.59 - Flaky test handling pattern.60 - Before/after timing expectations.6162## Examples6364A 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.6566## Edge Cases & Error Handling6768- **Monorepos**: Use workspace-aware tools (Nx, Turborepo, pnpm workspaces).69- **Flaky tests that are actually bugs**: Quarantine + create ticket, do not ignore.70- **Cache invalidation bugs**: Provide cache key best practices (hash of lockfile + OS).7172## Verification73741. Re-run the pipeline multiple times and record new average duration.752. Flaky test rate drops (tracked in CI logs or a dashboard).763. Cost report shows reduction (if applicable).774. Developers report faster feedback on PRs.785. Success: Pipeline is 30-70% faster, reliable, and cheaper while maintaining the same quality gates.7980## References8182- [GitHub Actions Caching](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows)83- [Turborepo Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)84- [Nx Affected](https://nx.dev/nx/affected)85- [Flaky Test Management](https://testing.googleblog.com/2021/04/flaky-tests-10-years-later.html)8687---88> Source: [Nikoxkx/Agent-Skills](https://github.com/Nikoxkx/Agent-Skills) — distributed by [TomeVault](https://tomevault.io).89<!-- tomevault:4.0:skill_md:2026-06-15 -->