A good pipeline is fast enough that developers wait for it, and trustworthy enough that a green check means 'safe to ship'. Most pipelines fail one or both. Here is the anatomy that gets both right.
Stages, in order of speed
- Lint and unit tests first - seconds, catch the most, fail fast
- Build once, produce an immutable artifact, reuse it everywhere
- Integration tests against ephemeral services
- Security scans (SAST, deps, container) as gates
- Deploy via GitOps or a gated step to production
Build once, promote the same artifact
build:
stage: build
script: docker build -t $IMG:$SHA . && docker push $IMG:$SHA
deploy:staging:
script: kubectl set image deploy/web web=$IMG:$SHA # same image, promoted
deploy:prod:
script: kubectl set image deploy/web web=$IMG:$SHA
when: manualRebuilding per environment is how 'it passed in staging' turns into a prod-only failure. Build a single artifact, test that artifact, and promote exactly it.
Fast because it parallelizes and caches; trustworthy because it tests the very bytes that ship.
Cache dependencies, parallelize independent stages, and promote one immutable artifact. That combination is what turns a 40-minute pipeline into a 6-minute one.