Fast feedback loops are the backbone of high-performing DevOps teams. Waiting 20 minutes for a pipeline to run tests or build artifacts slows down shipping and interrupts developer flow.
Here are five battle-tested techniques you can add to your .gitlab-ci.yml today to slash pipeline duration.
1. Optimize Caching with Directed Cache Keys
Re-downloading dependencies on every stage wastes valuable build minutes. Using dynamic cache keys based on lockfiles ensures that dependencies are cached and only refreshed when files change:
yaml
cache:
key:
files:
- package-lock.json # or yarn.lock, Gemfile.lock, poetry.lock
paths:
- .npm/
- node_modules/
2. Run Independent Jobs with needs (Directed Acyclic Graphs)
By default, stages execute sequentially (all build jobs finish before any test jobs start). Use the needs: keyword to let independent jobs start immediately without waiting for an entire stage to complete:
yaml
lint:
stage: test
needs: [] # Runs immediately as soon as the pipeline starts!
script:
- npm run lint
3. Use interruptible: true for Outdated Pipelines
If a developer pushes a new commit to a branch while a pipeline is already running, running the old pipeline to completion burns compute minutes. Set interruptible: true on your jobs:
yaml
default:
interruptible: true
New pushes will automatically cancel the redundant in-progress pipeline.
4. Narrow Artifact Paths and Set Short Retention Periods
Uploading multi-gigabyte build artifacts slows down runner handoffs and clutters storage. Keep artifact scopes minimal and expire them quickly for temporary test reports:
yaml
artifacts:
expire_in: 1 day
paths:
- dist/
5. Leverage Slim Pre-built Container Images
Using a generic heavyweight Linux image and installing dependencies with apt-get on every job adds 1–3 minutes of overhead. Instead, use official slim images or build your own custom runner image with tools pre-installed:
yaml
image: node:20-alpine # Smaller download footprint than node:20
5. Click **Publish** (blue button at the bottom/top).
6. **Copy the published URL** from your browser address bar (e.g. `https://dev.to/yourusername/...`).
---
Top comments (0)