RousselTMLEARNING

DevOps

GitLab CI/CD best practices and troubleshooting

Running GitLab CI/CD day to day: speeding up pipelines, controlling compute minutes, organizing files, debugging a job (CI_DEBUG_TRACE, gitlab-ci-local), frequent errors and checklist.

1. Speeding up #

Feedback in under 10 minutes.

Levers #

Optimizations
  • Dependency cache keyed on the lock file (cache:key:files).
  • needs for an execution graph instead of strict stages; rules:changes to only run what is affected.
  • interruptible: true cancels pipelines superseded by a newer push (with the project option "auto-cancel redundant pipelines").
  • Lightweight images prebuilt with the job's tools; artifacts with expire_in.

2. Debugging #

Understanding why a job fails.

Frequent errors #

SymptomLikely cause
"This job is stuck"no runner with the right tags, or protected runner and unprotected branch
Pipeline created twicebranch and merge request pipelines: add workflow:rules
Empty variableprotected variable used on an unprotected branch
Artifact not foundproducer job missing from needs or expired artifact
docker: Cannot connect to the Docker daemonmissing dind service or wrong DOCKER_HOST/TLS

The CI_DEBUG_TRACE: "true" variable shows every executed command (careful: secrets may appear). gitlab-ci-local replays a pipeline on your machine without pushing.

3. Checklist #

Before rolling out.

Checks #

ItemCheck
Reliabilityprotected main branch, pipeline required before merge
Speedunder 10 minutes for merge request feedback
SecuritySAST and secret detection, OIDC rather than keys, runners separated by trust
Deliverysame image promoted, tracked environments, rollback tested
Reuseversioned components rather than copy-paste
Best practice : Treat .gitlab-ci.yml as code: review, tests (glab ci lint) and versioning of shared components.

Commands to know #

Commands to know
  • npx gitlab-ci-local test : run the test job locally
  • glab ci trace : follow the current job log
  • glab api projects/:id/pipelines?status=failed : failed pipelines

Sources #

Checked in November 2026: CI/CD platforms change every month, check versions and plans in the vendor's documentation.

Related articles

GitLab CI/CD: concepts and architecture

Discover GitLab CI/CD: the DevSecOps platform, the .gitlab-ci.yml file, pipelines, stages and jobs, runners, …

Writing a .gitlab-ci.yml: jobs, rules, cache and artifacts

Mastering .gitlab-ci.yml syntax: stages, jobs and images, rules and workflow, needs (DAG), cache and artifact…

GitLab runners: types, executors, installation and security

Running GitLab jobs: instance, group and project runners, docker, kubernetes and docker-autoscaler executors,…

Keep learning

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!