Interview Prep/Jenkins/Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy

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.

All Jenkins questions Roadmap: Jenkins

More on Integrations: SonarQube, Nexus, Artifactory, Docker, Trivy