Trivy uses golang templates. Thus, whenever opening a tag {{an_opening_tag}}
, most likely it needs to be closed with {{end}}
.
For example:
The tag
range
works similarly to a for-each loop, where.
represents an initial object
{{range . as $myObj}}--- This a text concatenating {{$myObj.Target}} ---{{end}}
Closing a tag {{end}}
isn't necessary whenever reading a variable value, or assigning a new variable.
For example:
{{range . as $myObj}}{{$prefixTarget := cat "#" $myObj.Target}}--- This a text concatenating {{$prefixTarget}} ---{{end}}
Assume we have template file named yaml.tpl
, and it will help us create an YAML structure out of our trivy report:
Please note you can escape different characters using ascii codes: http://defindit.com/ascii.html
yaml_template=`cat yaml.tpl`
trivy image --format template --template "$yaml_template" -o trivy_report.yaml <IMAGE_NAME>