How do you scan an image with Trivy in a pipeline and gate on results?
IntermediateConceptIntegrations: SonarQube, Nexus, Artifactory, Docker, Trivy
Answer
container('trivy') {
sh '''
trivy image --input image.tar \
--severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 \
--format template --template "@contrib/junit.tpl" -o trivy-junit.xml
'''
}
post { always { junit allowEmptyResults: true, testResults: 'trivy-junit.xml' } }
--exit-code 1 fails the step when findings match. Cache the vulnerability DB (--cache-dir on a volume, or a mirrored --db-repository) so every build does not download it. Use .trivyignore with expiry comments for accepted risks.
More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy
How do you integrate SonarQube with a Jenkins pipeline?IntermediateHow does `waitForQualityGate` work?IntermediateHow do you deploy Maven artifacts to Nexus from Jenkins?IntermediateHow do you publish npm packages or pull dependencies through Nexus or Artifactory?BeginnerHow do you use JFrog Artifactory from Jenkins?IntermediateHow do you build and push a Docker image from Jenkins on a VM agent?Beginner