Skip to main content
In this guide, you’ll learn how to import a custom TrivyScanScript shared library into your Jenkins pipeline and run vulnerability scans at various severity levels. By centralizing your Trivy logic, you can maintain consistency across projects and simplify pipeline definitions.

Prerequisites

  • A Jenkins instance with Pipeline Shared Libraries enabled
  • A Git repository for your shared library
  • An application repository containing a Jenkinsfile
  • Docker image registry credentials (if needed)

1. Define the vulnerability Step in the Shared Library

In your shared library repo, open or create vars/TrivyScanScript.groovy and add the vulnerability function:
Commit and push these changes:

2. Invoke the Shared Library from Your Jenkinsfile

In your application repository, update the Jenkinsfile to load and call trivyScanScript.vulnerability:
Commit and push:

3. Troubleshooting: MissingPropertyException

If Jenkins logs show:
that usually means the loadScript invocation wasn’t using a string literal for the script name.
Ensure you wrap the script name in quotes. Otherwise, Groovy tries to resolve an undefined property.

4. Fixing the loadScript Invocation

Update vars/TrivyScanScript.groovy to use a quoted name:
Then:
Rerun or trigger the Jenkins build.

5. Verifying a Successful Run

After Jenkins picks up the fix, you should see output similar to:
You will also find the generated HTML reports under your build’s artifacts.

Conclusion

By extracting the Trivy vulnerability scan into a shared library step, you:
  • Promote reuse and consistency across pipelines
  • Reduce duplication in Jenkinsfiles
  • Simplify maintenance when updating scan logic
For more details on Trivy and Jenkins integration, see:

Watch Video