Enhance your Jenkins CI/CD workflow by integrating a custom TrivyScan shared library. This guide walks you through creating the library, configuring Jenkins, referencing a feature branch, invoking scan methods, handling common errors, and reviewing pipeline artifacts. In this tutorial we will cover:Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
- Creating the
TrivyScanGroovy script - Configuring a global trusted library in Jenkins
- Referencing a feature branch in the
Jenkinsfile - Invoking library methods (
vulnerabilityandreportsConverter) - Handling “method calls not allowed” errors
- Reviewing the final pipeline run and published artifacts
1. TrivyScan Groovy Script
Start by creating a new Git branch and adding theTrivyScan.groovy file under vars/. This shared library defines two methods:
| Method Name | Purpose | Output Files |
|---|---|---|
| vulnerability | Scan Docker image for vulnerabilities | trivy-image-MEDIUM-results.json, trivy-image-CRITICAL-results.json |
| reportsConverter | Convert JSON scan reports to HTML and JUnit | trivy-image-MEDIUM-results.html, trivy-image-CRITICAL-results.html, *.xml |
Branching allows you to test changes in
featureTrivyScan without affecting your main pipeline.2. Configure Global Trusted Library in Jenkins
As a Jenkins administrator:- Navigate to Manage Jenkins > Configure System > Global Pipeline Libraries.
-
Add a new library:
- Name:
dasher-trusted-shared-library - Default version:
main - Allow default version to be overridden: Enabled
- Name:

Enabling “default version override” lets you specify feature branches like
featureTrivyScan in your Jenkinsfile.3. Reference the Feature Branch in Your Jenkinsfile
At the top of yourJenkinsfile, use the @Library annotation to load the shared library from the featureTrivyScan branch:
4. Invoking Shared-Library Methods
In declarative pipelines, all calls to shared-library methods (for example,trivyScan.vulnerability(...)) must be wrapped inside a script block:
5. Handling Common “Method Calls Not Allowed” Errors
If you encounter an error like:script { ... } section, as shown above.
6. Reviewing Pipeline Run and Artifacts
Once you push your updatedJenkinsfile, your pipeline (e.g., build #8) will:
- Fetch your shared library from
featureTrivyScan - Execute Trivy vulnerability scans
- Convert JSON results into HTML/JUnit reports

Summary
- Add your Groovy methods under
vars/TrivyScan.groovy. - Enable “default version override” in Jenkins global libraries.
- Reference your feature branch with
@Library. - Wrap all shared-library method calls in
scriptblocks. - Use
trivyScan.vulnerability(...)andtrivyScan.reportsConverter()for scanning and report conversion. - Publish results with
publishHTML.
Jenkinsfile clean, reusable, and easy to maintain.