← All insightsIntegration

How to use GitLab CI/CD with Trivy

Nir Geier, CodeWizard · 1 May 2025 · 3 min read · Intermediate

GitLab CI/CD and Trivy are a common pairing in a modern DevOps stack. Here is how they fit together and a practical way to wire them up.

Where GitLab CI/CD fits

GitLab CI/CD runs pipelines defined in .gitlab-ci.yml on GitLab Runners, with stages, jobs, environments and built-in DevSecOps scanning - all in one platform next to the repo.

yaml
stages: [build, test, deploy]
cache: { paths: [node_modules/] }

build:
  stage: build
  image: node:20
  script: [npm ci, npm run build]

test:
  stage: test
  image: node:20
  script: [npm test]

deploy:prod:
  stage: deploy
  script: [./deploy.sh]
  environment: { name: production }
  when: manual
  rules: [{ if: '$CI_COMMIT_BRANCH == "main"' }]

Where Trivy fits

Trivy is an open-source security scanner that finds CVEs, misconfigurations, secrets and license issues across container images, filesystems, Git repos, IaC and live Kubernetes clusters.

yaml
# trivy.yaml
severity:
  - HIGH
  - CRITICAL
vulnerability:
  ignore-unfixed: true
exit-code: 1

Making them work together

  • Use stages and needs: for a fast DAG pipeline
  • Cache dependencies and pass build output as artifacts
  • Gate on HIGH/CRITICAL with ignore-unfixed, then tighten over time
  • Scan images, IaC and filesystems - not just one surface

Want this pairing set up properly, with docs and handover? That is exactly the kind of work CodeWizard's embedded senior engineers do - and both GitLab CI/CD and Trivy have active community groups you can join for free.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult