Optimize Pipeline
Analyze and optimize Harness CI/CD pipeline performance through parallel testing, caching, bottleneck analysis, and monorepo strategies.
Instructions
Step 1: Establish Scope
Confirm the service, pipeline, and current performance baseline.
Call MCP tool: harness_list
Parameters:
resource_type: "pipeline"
org_id: "<organization>"
project_id: "<project>"
Get recent execution timing data:
Call MCP tool: harness_list
Parameters:
resource_type: "execution"
org_id: "<organization>"
project_id: "<project>"
pipeline_id: "<pipeline_identifier>"
Step 2: Identify the Optimization Task
Determine which optimization the user needs:
- Parallel Testing with Test Intelligence -- Split tests across runners and skip unchanged tests
- Caching Strategy -- Multi-layer dependency, build output, and test result caching
- Pipeline Bottleneck Analysis -- Stage-level timing breakdown with recommendations
- Cache Hit Rate Improvement -- Diagnose and fix low cache hit rates
- Monorepo CI Pipeline -- Selective builds triggered by changed paths
Step 3: Configure Parallel Testing with Test Intelligence
Gather from the user:
- Test framework (JUnit, pytest, Jest, Go test, etc.)
- Total test count and current runtime
- Target runtime
Design the parallel test strategy:
- Split tests across N parallel runners using Harness Test Intelligence
- Use TI to identify and skip unchanged tests based on code changes
- Configure test splitting method: by class, by file, or by timing data
- Set up test result aggregation across runners
- Track TI savings over time (tests skipped vs. total)
Configuration:
- Enable Test Intelligence in the pipeline stage
- Set parallelism level based on test count and runner capacity
- Configure test report collection from all parallel runners
- Set up failure thresholds (e.g., fail the stage if any runner fails)
Step 4: Design Caching Strategy
Gather from the user:
- Build tool (Maven, Gradle, npm, yarn, pip, Go modules)
- Current build time breakdown (dependency download, compile, test)
- Cache key source (lockfile hash, manifest hash)
Design multi-layer caching:
Layer 1 -- Dependencies:
- Cache key: hash of lockfile (package-lock.json, pom.xml, go.sum)
- Cache path: dependency directory (~/.m2, node_modules, ~/.cache/pip)
- Fallback: use previous cache if exact match not found
Layer 2 -- Build outputs:
- Cache key: hash of source files
- Cache path: build output directory (target/, dist/, build/)
- Invalidation: any source file change
Layer 3 -- Test results:
- Cache key: hash of source + test files
- Cache path: test result and coverage directories
- Use to skip unchanged tests in combination with TI
Set cache TTL (recommended 7-14 days) with fallback strategy.
Step 5: Analyze Pipeline Bottlenecks
Pull execution data and break down by stage:
Call MCP tool: harness_get
Parameters:
resource_type: "execution"
resource_id: "<execution_id>"
org_id: "<organization>"
project_id: "<project>"
For each stage, identify:
- Duration vs. pipeline total (find the longest stages)
- Queue time vs. execution time (runner availability issues)
- Sequential stages that could run in parallel
- Steps that download large artifacts repeatedly
Produce a prioritized optimization list ranked by time savings.
Step 6: Design Monorepo CI Pipeline
Gather from the user:
- Number of services and their directories
- Shared libraries and their dependents
- Build tool
Design selective builds:
- Use path-based triggers: only build services with changed files
- Build shared libraries when they change, then rebuild all dependents
- Run integration tests only when cross-service dependencies change
- Use a dependency graph to determine the minimal build set
Examples
- "My pipeline takes 45 minutes, help me speed it up" -- Analyze bottlenecks and recommend parallel testing, caching, and stage reordering
- "Set up parallel tests with Test Intelligence" -- Configure TI with test splitting across N runners
- "Improve our cache hit rate" -- Diagnose cache key configuration and fix common misses
- "Design a CI pipeline for our monorepo with 5 services" -- Configure path-based triggers with selective builds
- "Our builds download dependencies every time" -- Design multi-layer caching strategy with fallback
Performance Notes
- Test Intelligence needs 2-3 full test runs to build its initial model -- first runs will execute all tests.
- Cache keys should be based on lockfiles, not timestamps -- timestamps cause unnecessary cache misses.
- Parallelism beyond runner capacity causes queuing -- profile available runner capacity before increasing parallelism.
- Monorepo path triggers should include shared library directories to avoid missing transitive changes.
Troubleshooting
Test Intelligence Not Skipping Tests
- Verify TI is enabled and has completed baseline runs
- Check that the test framework is supported by Harness TI
- Ensure test report format is correctly configured for the framework
Cache Misses on Every Build
- Check cache key configuration -- keys should use file hashes, not timestamps
- Verify cache path matches the actual dependency directory
- Check that the cache storage backend is accessible from all runners
Monorepo Building Everything
- Verify path-based triggers are configured correctly
- Check that the dependency graph includes shared library paths
- Ensure glob patterns in triggers match the actual directory structure
1---2name: optimize-pipeline3description: Optimize Harness CI/CD pipeline performance via MCP. Configure parallel test execution with Test Intelligence, design multi-layer caching strategies, analyze pipeline bottlenecks with stage-level timing breakdowns, optimize cache hit rates, and design monorepo CI pipelines with selective builds. Use when asked to speed up pipelines, improve cache hit rates, set up parallel testing, optimize build times, or configure monorepo builds. Do NOT use for creating new pipelines (use create-pipeline instead) or debugging failures (use debug-pipeline instead). Trigger phrases: pipeline speed, slow pipeline, cache hit rate, parallel tests, test intelligence, build optimization, caching strategy, monorepo pipeline, pipeline bottleneck, build speed.4license: Apache-2.05---67# Optimize Pipeline89Analyze and optimize Harness CI/CD pipeline performance through parallel testing, caching, bottleneck analysis, and monorepo strategies.1011## Instructions1213### Step 1: Establish Scope1415Confirm the service, pipeline, and current performance baseline.1617```18Call MCP tool: harness_list19Parameters:20 resource_type: "pipeline"21 org_id: "<organization>"22 project_id: "<project>"23```2425Get recent execution timing data:2627```28Call MCP tool: harness_list29Parameters:30 resource_type: "execution"31 org_id: "<organization>"32 project_id: "<project>"33 pipeline_id: "<pipeline_identifier>"34```3536### Step 2: Identify the Optimization Task3738Determine which optimization the user needs:39401. **Parallel Testing with Test Intelligence** -- Split tests across runners and skip unchanged tests412. **Caching Strategy** -- Multi-layer dependency, build output, and test result caching423. **Pipeline Bottleneck Analysis** -- Stage-level timing breakdown with recommendations434. **Cache Hit Rate Improvement** -- Diagnose and fix low cache hit rates445. **Monorepo CI Pipeline** -- Selective builds triggered by changed paths4546### Step 3: Configure Parallel Testing with Test Intelligence4748Gather from the user:49- Test framework (JUnit, pytest, Jest, Go test, etc.)50- Total test count and current runtime51- Target runtime5253Design the parallel test strategy:54- Split tests across N parallel runners using Harness Test Intelligence55- Use TI to identify and skip unchanged tests based on code changes56- Configure test splitting method: by class, by file, or by timing data57- Set up test result aggregation across runners58- Track TI savings over time (tests skipped vs. total)5960Configuration:61- Enable Test Intelligence in the pipeline stage62- Set parallelism level based on test count and runner capacity63- Configure test report collection from all parallel runners64- Set up failure thresholds (e.g., fail the stage if any runner fails)6566### Step 4: Design Caching Strategy6768Gather from the user:69- Build tool (Maven, Gradle, npm, yarn, pip, Go modules)70- Current build time breakdown (dependency download, compile, test)71- Cache key source (lockfile hash, manifest hash)7273Design multi-layer caching:7475**Layer 1 -- Dependencies:**76- Cache key: hash of lockfile (package-lock.json, pom.xml, go.sum)77- Cache path: dependency directory (~/.m2, node_modules, ~/.cache/pip)78- Fallback: use previous cache if exact match not found7980**Layer 2 -- Build outputs:**81- Cache key: hash of source files82- Cache path: build output directory (target/, dist/, build/)83- Invalidation: any source file change8485**Layer 3 -- Test results:**86- Cache key: hash of source + test files87- Cache path: test result and coverage directories88- Use to skip unchanged tests in combination with TI8990Set cache TTL (recommended 7-14 days) with fallback strategy.9192### Step 5: Analyze Pipeline Bottlenecks9394Pull execution data and break down by stage:9596```97Call MCP tool: harness_get98Parameters:99 resource_type: "execution"100 resource_id: "<execution_id>"101 org_id: "<organization>"102 project_id: "<project>"103```104105For each stage, identify:106- Duration vs. pipeline total (find the longest stages)107- Queue time vs. execution time (runner availability issues)108- Sequential stages that could run in parallel109- Steps that download large artifacts repeatedly110111Produce a prioritized optimization list ranked by time savings.112113### Step 6: Design Monorepo CI Pipeline114115Gather from the user:116- Number of services and their directories117- Shared libraries and their dependents118- Build tool119120Design selective builds:121- Use path-based triggers: only build services with changed files122- Build shared libraries when they change, then rebuild all dependents123- Run integration tests only when cross-service dependencies change124- Use a dependency graph to determine the minimal build set125126## Examples127128- "My pipeline takes 45 minutes, help me speed it up" -- Analyze bottlenecks and recommend parallel testing, caching, and stage reordering129- "Set up parallel tests with Test Intelligence" -- Configure TI with test splitting across N runners130- "Improve our cache hit rate" -- Diagnose cache key configuration and fix common misses131- "Design a CI pipeline for our monorepo with 5 services" -- Configure path-based triggers with selective builds132- "Our builds download dependencies every time" -- Design multi-layer caching strategy with fallback133134## Performance Notes135136- Test Intelligence needs 2-3 full test runs to build its initial model -- first runs will execute all tests.137- Cache keys should be based on lockfiles, not timestamps -- timestamps cause unnecessary cache misses.138- Parallelism beyond runner capacity causes queuing -- profile available runner capacity before increasing parallelism.139- Monorepo path triggers should include shared library directories to avoid missing transitive changes.140141## Troubleshooting142143### Test Intelligence Not Skipping Tests144- Verify TI is enabled and has completed baseline runs145- Check that the test framework is supported by Harness TI146- Ensure test report format is correctly configured for the framework147148### Cache Misses on Every Build149- Check cache key configuration -- keys should use file hashes, not timestamps150- Verify cache path matches the actual dependency directory151- Check that the cache storage backend is accessible from all runners152153### Monorepo Building Everything154- Verify path-based triggers are configured correctly155- Check that the dependency graph includes shared library paths156- Ensure glob patterns in triggers match the actual directory structure