In this guide, you’ll learn how to import a customDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
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:
| Command | Description |
|---|---|
git checkout -b featureTrivyScan | Create a feature branch |
git add vars/TrivyScanScript.groovy | Stage the new step definition |
git commit -m "Add TrivyScanScript.vulnerability step" | Commit with a clear message |
git push -u origin featureTrivyScan | Push branch to remote |
2. Invoke the Shared Library from Your Jenkinsfile
In your application repository, update the Jenkinsfile to load and call trivyScanScript.vulnerability:
3. Troubleshooting: MissingPropertyException
If Jenkins logs show:
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:
5. Verifying a Successful Run
After Jenkins picks up the fix, you should see output similar to: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