Skip to content

Instantly share code, notes, and snippets.

@jplitza
Created January 10, 2025 13:37
Show Gist options
  • Save jplitza/3983d70b5fbbb82a6b8578e990e22cc3 to your computer and use it in GitHub Desktop.
Save jplitza/3983d70b5fbbb82a6b8578e990e22cc3 to your computer and use it in GitHub Desktop.
Convert output from `kyverno apply -p` (converted to JSON) to JUnit XML format using `jq`
@html "<testsuite name=\"kyverno\" tests=\"\(.summary|add)\" failures=\"\(.summary.fail)\" skipped=\"\(.summary.skip)\" errors=\"\(.summary.error)\">",
(.results | group_by(.policy) | .[] | [
@html "<testsuite name=\"\(.[0].policy)\">",
(group_by(.rule) | .[] | [
"<testsuite name=\"\(.[0].policy).\(.[0].rule)\">",
(.[] | [
@html "<testcase name=\"\(.policy).\(.rule).\(.resources[0].namespace)/\(.resources[0].kind)/\(.resources[0].name)\">",
(if .result == "fail"
then @html "<failure message=\"\(.message)\" />"
else if .result == "skip"
then @html "<skipped message=\"\(.message)\" />"
else ""
end
end),
"</testcase>"
] | join("\n")),
"</testsuite>"
] | join("\n")),
"</testsuite>"
] | join("\n")),
"</testsuite>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment