this is my first time working with trivy and clair on Azure DevOps using self-hosted agent and I just tried this pipeline that I have found on GitHub
name: $(BuildDefinitionName)_$(date:yyyyMMdd)_$(BuildID)$(rev:.r)
resources:
- repo: self
variables:
image_name: openjdk
image_tag: 17-jdk-slim
jobs:
- job: TrivyScanContainerImage
displayName: Scan container image by Trivy
steps:
- script: |
mkdir report
trivy image -s HIGH,CRITICAL $(image_name):$(image_tag) | tee ./report/trivy-image-scan-report.txt
displayName: "Image scan by Trivy"
continueOnError: true
- publish: ./report
artifact: ImageScans
displayName: Publish Clair Scan Report
condition: always()
I want to know how to make it work for mutliple containers.
2
Answers
Instead of using variables you can declare a parameter containing an array of images to scan and then use a loop to generate a job for each one.
Example:
Running the pipeline:
You can use a parameter to pass multiple images like as below.
By this way, in the same job, it will generate a copy of "
Image scan by Trivy
" step for scanning each image and generating the scan report file for each image into the report folder. Then use one "Publish Clair Scan Report
" steps to publish all the reports.