0

I want to integrate my ChefSpecs with Jenkins in a way that there is one Jenkins job that runs all specs of all cookbooks and prints one summary. Unfortunately that doesn't seem as easy as I have thought. Writing a simple Rakefile that creates a rspec rake task (like when testing standard Ruby specs) won't help because rspec expects a Berksfile in the directory from which it is called.

So there seem to be only two ways to test cookbook specs ...

  • Creating a Jenkins job for each and every cookbook
  • Iterating manually through the cookbooks in Jenkins and calling rspec in each cookbook I find. Which will not print a summary of all tests and seems stupid anyway for multiple other reasons.

What is the recommended way here? Do I need to create a seperate job for every cookbook or is there a better way? Especially in combination with Berkshelf?

I can see the advantages of having a job for every cookbook's spec but that also means doing a git pull for dozens of cookbooks from the same repo. We currently use the "all cookbooks in one repo"-approach

Cheers, Stefan

Stefan Marbury
  • 187
  • 1
  • 13
  • This might be a bit opinion-based. I haven't set it up completely, but I will use [Jenkins Job DSL](https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin) to generate the jobs. Which jobs to generate can be e.g. retrieved from the Github API (see [this question](http://stackoverflow.com/questions/23577933/generate-jenkins-jobs-for-all-github-repos)). And I think you should have one job per cookbook. – StephenKing Apr 14 '15 at 17:11

1 Answers1

0

If you can re-organize git repositories of your cookbooks, try following:

  1. Having following directory structure

    Vagrantfile Gemfile Berksfile cookbooks/cookbook_a/metadata.rb cookbooks/cookbook_a/recipes/recipe_1.rb cookbooks/cookbook_a/recipes/recipe_2.rb cookbooks/cookbook_b/metadata.rb cookbooks/cookbook_b/recipes/recipe_5.rb cookbooks/cookbook_b/recipes/recipe_6.rb spec/spec_helper.rb spec/cookbook_a/recipe_1_spec.rb spec/cookbook_a/recipe_2_spec.rb spec/cookbook_b/recipe_5_spec.rb spec/cookbook_a/recipe_6_spec.rb

  2. execute following 1 command:

    bundle exec rspec spec

This will execute chefspec for all the cookbook found under spec/ directory. And my Jenkins job is contains above command.

Joel Handwell
  • 742
  • 1
  • 10
  • 18