Created
January 10, 2025 13:37
-
-
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`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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