Better Chef Reporting for Automated Pipelines
When building your Chef cookbooks, you likely will want an automated pipeline which allows you to enforce a quality bar for how your cookbooks are developed.
However, you probably want a little more visibility than "did that build succeed", and want to be able to drill into exactly what failed. To do this, across many automated build platforms, like Jenkins, you want to produce a (well) supported machine-parseable format.
One of the most commonly usable formats is the JUnit output format, made popular with the Java testing library JUnit.
Fortunately, all of the Chef tools that we would want to use in a pipeline support the JUnit report format.
Cookstyle
Because Cookstyle is built upon the wonderful Rubocop, which means we can use the inbuild formatters that Rubocop provides, such as the built-in JUnit formatter:
rubocop --format junit --out test-reports/junit.xml
# or, only show failed Cops
rubocop --format junit --out test-reports/junit.xml --display-only-failed
RSpec
Unfortunately RSpec doesn't, out of the box, support JUnit format, but there's a great gem rspec_junit_formatter
which when installed, allows us to run:
rspec --format RspecJunitFormatter --out test-reports/rspec.xml
Test Kitchen + InSpec
Test Kitchen fortunately supports JUnit format results out-of-the-box:
verifier:
name: inspec
reporter:
- cli
- junit:path/to/results/%{platform}_%{suite}_inspec.xml