You now know every piece: stages and needs, artifacts and caches, rules, variables, runners, Docker builds, tests, scanners, environments, OIDC deploys and components. This last lesson collects the habits that separate a pipeline people trust from one they work around, then shows the complete Orbit pipeline built over the course.
1. Treat feedback time as a budget
A merge request pipeline is a promise to the developer: you will know within N minutes. Set N (ten is a good target) and defend it.
- Fail fast. Lint and type checks start with
needs: []and finish in seconds. A missing semicolon should not wait for a Docker build. - **Shape the graph with
needs.** Every job starts as soon as its real inputs exist. - Cache downloads, keyed on lock files, never on branch names alone.
- Parallelise slow suites with
paralleland test sharding. - Skip what did not change on merge requests with
rules:changes; run everything onmain. - Move slow suites after the merge or to a nightly schedule when they do not need to block.
- Cancel outdated pipelines with
interruptibleandauto_cancel.
2. Make every run reproducible
The same commit should produce the same result today and in six months.
- Pin images to versions, and to digests for anything that deploys:
node:24-alpine@sha256:…. - Pin includes and components to tags or SHAs.
- Install from lock files (
npm ci,pip install -r requirements.lock,go mod download). - Build once, deploy many. Build the image in one job, tag it with the commit, and deploy that exact image to staging and production. Never rebuild for production.
- Keep scripts runnable locally. Put real logic in
ci/*.shscripts that work on a laptop too; keep YAML for wiring.
3. Keep the YAML readable
Pipelines are code that everyone reads and nobody owns, unless you make them easy to own.
- Put shared setup in
default:and hidden jobs used withextends. - Split long files with
include: localby concern:ci/build.yml,ci/test.yml,ci/deploy.yml. - Share across repositories with versioned CI/CD components, not copy-paste.
- Name jobs by what they do (
deploy-api-staging), not by number (job3). - Give pipelines readable names with
workflow:name. - Add a short comment above anything surprising. The next person to read it is you in a year.
- Validate in the pipeline editor or with
glab ci lintbefore pushing.
4. Least privilege everywhere
- Protected branches and tags for
mainand releases; nobody pushes directly. - Protected, masked and hidden variables, scoped to environments.
- OIDC for cloud access, one role per environment, trust policies that check project and ref.
- Protected runners for deploys; no privileged mode on shared runners.
- Job token allowlist limited to projects that need it.
- CODEOWNERS on
.gitlab-ci.ymlandci/so pipeline changes get a platform review. - Scanners for secrets, code, dependencies and images, with high findings blocking merges.
5. Make deploys boring
- Every deploy job has an
environmentso it is tracked and can be rolled back. - Deploys use
resource_groupandinterruptible: false. - Deploy jobs wait for health (
ecs wait,kubectl rollout status, a smoke test) instead of passing on “request accepted”. - Database migrations are backward compatible for one release, so rollback stays possible.
- Production is a manual job or an approval until monitoring and rollback have earned your trust.
6. Keep costs and storage in check
- Set
expire_inon artifacts; keep long-lived results in a registry instead. - Turn on a container registry cleanup policy.
- Use small runner sizes for small jobs; reserve big machines for builds that need them.
- Watch compute minute usage under the group’s Usage quotas page.
- Add
timeoutto jobs that call external systems so a hang does not burn an hour.
7. Measure the pipeline like a product
Open Analyze → CI/CD analytics regularly and track:
| Metric | Healthy sign |
|---|---|
| Merge request pipeline duration | Stable and under your budget |
Success rate on main | Above 90%; red main is fixed within the hour |
| Most failed jobs | Not the same flaky job week after week |
| Deployment frequency | Steady or rising (DORA metrics, from environments) |
| Lead time for changes | Shrinking as the pipeline gets faster |
Pick the worst number each month and fix it. Pipeline health decays quietly if nobody watches it.
Anti-patterns to avoid
| Anti-pattern | Why it hurts | Do this instead |
|---|---|---|
image: node:latest | Builds change without any commit | Pin versions and digests |
| Long-lived cloud keys in variables | One leak exposes production | OIDC with short-lived credentials |
retry: 2 on test jobs | Hides flaky tests | Quarantine and fix them |
| Rebuilding the image for production | Production runs untested bytes | Build once, promote the same tag |
Deploying latest | Rollback is impossible | Immutable commit or version tags |
| One giant 800-line file | Nobody dares to change it | Includes and components |
allow_failure: true everywhere | Red jobs become wallpaper | Only for genuinely optional checks |
only / except | Limited, legacy syntax | rules |
| Printing the environment for debugging | Leaks secrets into logs | Print specific non-secret variables |
The complete Orbit pipeline
Here is the main .gitlab-ci.yml, with details moved into included files exactly as the course built them:
# Orbit: build, test, scan, ship.
workflow:
name: "$CI_PIPELINE_SOURCE: $CI_COMMIT_REF_NAME"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "schedule"
auto_cancel:
on_new_commit: interruptible
stages: [build, test, package, deploy, verify]
default:
image: node:24-alpine
interruptible: true
retry:
max: 2
when: [runner_system_failure, stuck_or_timeout_failure]
include:
- local: ci/build.yml # build-api, build-web
- local: ci/test.yml # lint, unit-tests, integration-tests
- local: ci/image.yml # build-image, push-ecr
- local: ci/deploy.yml # review apps, staging, production
- component: $CI_SERVER_FQDN/components/secret-detection/secret-detection@~latest
- component: $CI_SERVER_FQDN/components/sast/sast@~latest
- template: Jobs/Container-Scanning.gitlab-ci.yml
container_scanning:
needs: [build-image]
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
Replace ~latest with fixed component versions once you have tested them. And the flow it produces:
merge request:
lint ─────────────────────────────┐
build-api ─▶ unit-tests (x2) │
─▶ integration-tests ├─▶ build-image ─▶ container_scanning
build-web ─▶ web-tests │ ─▶ deploy-review ─▶ e2e-tests
secret_detection, semgrep-sast ───┘
main:
...same checks... ─▶ push-ecr ─▶ deploy-staging ─▶ trigger-e2e
─▶ deploy-production (manual, protected)
Every piece maps to a lesson:
| Piece | Lesson |
|---|---|
| Stages, needs, artifacts, cache | 3 |
| Variables, protected secrets, job token | 4 |
| Runners and tags | 5 |
workflow:rules, auto_cancel, manual production | 6 |
Environments, review apps, resource_group | 7 |
| Docker image with an immutable tag | 8 |
| JUnit, coverage, parallel tests | 9 |
| Secret detection, SAST, container scanning | 10 |
| OIDC deploy to ECR, ECS, S3 and CloudFront | 11 |
| Includes, components, multi-project triggers | 12 |
A checklist for any new pipeline
- Lint and unit tests run on every merge request and finish in minutes.
mainis protected and its pipeline must pass before merging.- Images and includes are pinned.
- Artifacts expire; caches are keyed on lock files.
- The build happens once; deploys promote the same artifact.
- Secrets are protected and masked, or replaced by OIDC.
- Deploy jobs have environments, resource groups and health checks.
- Security scanners run and high findings block the merge.
- Pipeline changes are reviewed by their owners.
- Someone looks at CI/CD analytics every month.
Exercise
The production deploy job runs docker build again so the image includes production settings. What is the problem?
Show answer
Answer: C. A rebuild can pick up different base layers or dependencies than the image you tested on staging. Build once, inject environment-specific settings at runtime and deploy the same immutable tag everywhere.
Exercise
Your merge request pipeline takes 25 minutes. Which change gives developers faster feedback without dropping any checks?
Show answer
Answer: B. Fail-fast ordering, caching, a needs graph and parallel test splitting shorten the critical path while keeping every check. The other options either hide failures or remove safety.
Key takeaways
- Treat feedback time as a budget and defend it with fail-fast ordering, needs, caching and parallelism.
- Reproducibility comes from pinned images and includes, lock files and building once.
- Readable pipelines use defaults, extends, includes and components instead of copy-paste.
- Least privilege applies to branches, variables, runners, tokens and cloud roles.
- Deploys should be tracked, serialised, health-checked and easy to roll back.
- Measure pipeline health and fix the worst number regularly.
FAQ
Where should I start if my current pipeline is a mess?
Measure first: duration, success rate and the most failing jobs. Then fix in this order: secrets and protected branches, a red main, the slowest step on the critical path, and finally YAML structure.
How do I convince my team to keep main green?
Make red visible (pipeline status in chat, a badge on the README), make the fix fast (small merges, clear logs), and agree that a red main beats any feature work. Merge trains on GitLab Premium also stop broken combinations from landing.
Should every project have the same pipeline?
The same building blocks, not the same file. Shared components give consistency for build, test, scan and deploy, while each project wires them for its own needs.
What should I learn after this course?
GitOps with Argo CD or Flux for Kubernetes deploys, progressive delivery (canaries and feature flags), and infrastructure pipelines for Terraform. The Terraform Tutorial covers the last one, including a full CI pipeline for infrastructure.
How do these practices translate to GitHub Actions?
Almost directly: jobs and needs, caches and artifacts, environments with protection rules, OIDC to AWS with id-token: write, reusable workflows instead of components. The habits matter more than the keywords.