Skip to main content
Before pushing your Docker image to a registry, it’s crucial to identify and remediate vulnerabilities. In this guide, we’ll walk through how to use Trivy for vulnerability scanning and integrate it into a Jenkins pipeline.

What Is Trivy?

Trivy is an open-source, all-in-one security scanner from Aqua Security. It can analyze:
  • Container images
  • File systems
  • Git repositories
  • Kubernetes manifests
  • Infrastructure as Code (IaC)
Trivy detects OS package vulnerabilities, software dependency issues, IaC misconfigurations, license risks, and exposed secrets.
The image is a screenshot of a webpage from Aqua Security's documentation about Trivy, a security scanner. It lists the targets Trivy can scan, such as container images and filesystems, and the types of issues it can detect, like known vulnerabilities and sensitive information.
Learn more on the official Trivy GitHub repository.

Installing Trivy

You can install Trivy via package managers, a standalone binary, or run it in Docker.

Homebrew (macOS)

Docker

RPM-Based Linux

Manual / From Source

Basic Usage

Scan a Docker image for vulnerabilities:
Scan a local project directory for vulnerabilities and secrets:
Get Trivy version and help:
By default, Trivy exits with code 0 even if it finds non-critical issues. Use --exit-code to control build failures based on severity.

Integrating Trivy into a Jenkins Pipeline

Add a Trivy Vulnerability Scanner stage immediately after your Docker build. Below is an example declarative pipeline:
The critical-scan stage uses --exit-code 1. Any CRITICAL vulnerability will fail the build immediately.

Supported Reporting Formats

Trivy supports several output formats: Templates are installed at:
The image shows a webpage from Trivy's documentation, detailing the reporting formats supported by Trivy, such as Table, JSON, and Template. The page includes a table listing supported scanners and a command example.
To convert a JSON output into a CycloneDX SBOM:

Reviewing Scan Results

After your Jenkins job completes, the workspace will contain:
The image shows a Jenkins workspace interface displaying a list of files and folders with their names, sizes, and timestamps.
  • trivy-image-medium.html / .json / .xml
  • trivy-image-critical.html / .json / .xml
In Jenkins’ Test Results view, Trivy’s JUnit entries appear alongside other CI tests:
The image shows a test report from a CI/CD pipeline indicating that 57 tests have failed, with details of existing failures including various CVE vulnerabilities.

Adjusting Severity Thresholds

To treat HIGH severity like MEDIUM (only fail on CRITICAL), include HIGH in the non-failing scan:

Summary

In this tutorial, you learned how to:
  • Install Trivy on various platforms
  • Execute basic vulnerability scans on images and filesystems
  • Integrate Trivy into a Jenkins pipeline with pass/fail thresholds
  • Convert JSON results to HTML, JUnit, or CycloneDX formats
  • Publish and review vulnerability reports in Jenkins
Trivy also supports scanning IaC files, detecting sensitive data, and auditing software licenses. For advanced scenarios, visit the official Trivy documentation.

Watch Video