Successfully reported this slideshow.
Your SlideShare is downloading. ×

CLUG 2014-10 - Cookbook CI with Jenkins

Loading in …3

Check these out next

1 of 40 Ad

More Related Content

Slideshows for you (20)

Similar to CLUG 2014-10 - Cookbook CI with Jenkins (20)


Recently uploaded (20)

CLUG 2014-10 - Cookbook CI with Jenkins

  1. 1. Cookbook CI with Jenkins Part 1
  2. 2. Who Am I? • "zts" most places on the internet • Mostly Ops, Background, Mostly • Co-founder Elastera
  3. 3. Who Are You?
  4. 4. Cookbook Testing • foodcritic, chefspec, test-kitchen • Get things right • Keep things right
  5. 5. CI Servers • System for running actions on every commit • Identify problems early • Jenkins, GoCD, TravisCI, Wercker, etc
  6. 6. Why Jenkins? • Mature • Extensible • Good Chef Cookbook • Free
  7. 7. Why Not Jenkins? • TMTOWTDI • XML, so much XML • Automation is not a joy
  8. 8. Jenkins Cookbook • Install Jenkins & Plugins • Create jobs • Run commands and scripts
  9. 9. Previously… • Cooking With Jenkins • ...and Kitchen, and Docker
  10. 10. Subsequently… • Federated Jenkins with Chef • github:erichelgeson/jenkins-chef-dsl/
  11. 11. Basic Configuration • Install Plugins • Configure Plugins • Configure Jenkins
  12. 12. Installing Plugins • Idempotent • No dependency resolution • Restart may be required
  13. 13. Plugin Configuration • XML :( • ...containing module version strings :(( • Hold nose and use cookbook_file
  14. 14. Jenkins Configuration
  15. 15. Creating Jobs • jenkins_job • Job DSL plugin • Jenkins Job Builder
  16. 16. Pipeline • Foodcritic • Chefspec • Kitchen • Publish
  17. 17. And after publish? • That's why this is Part 1...
  18. 18. Foodcritic • Warnings plugin :) • XML config :(
  19. 19. Chefspec • yarjuf gem • Publish JUnit test result report
  20. 20. Test Kitchen • kitchen-docker • Matrix jobs • EnvInject and AnsiColor plugins
  21. 21. Berkshelf • upload to Chef server • record version as artifact
  22. 22. Berkshelf • curl -s https://jenkins.example/job/berks-upload/ lastSuccessfulBuild/artifact/VERSION
  23. 23. Gluing it together • Publish Artifact • Copy Artifact • Build Pipeline
  24. 24. Pipelines • Build Pipeline plugin • Build Graph View plugin • Build Flow DSL • ...and more
  25. 25. Build Pipeline
  26. 26. What's Missing? • JUnit output from serverspec • View most recent run of all pipelines • Notifications
  27. 27. Not the whole story... • Testing a set of cookbooks • Testing multiple nodes • Promoting releases
  28. 28. Summary • Not that hard to get started • Immediately valuable • Share your work!
  29. 29. Questions?
  30. 30. Resources
  31. 31. Thankyou Twitter: @zts email:

Editor's Notes

  • Yes, we’re hiring.
  • Let’s get the “hands up” out of the way…
    Who tests their cookbooks, chefspec and/or kitchen?
    Who practices TDD for their cookbooks?
    Who automatically runs tests on commits?
  • Not here to sell you on TDD, but it’s worth trying if you haven’t. Can encourage better design, as well as building a library of useful tests.
  • Addresses a problem on large, shared codebases - parallel streams of activity, on branches, taking a lot of effort to merge. Not such a huge problem on single cookbook repo’s (in my experience).
    However, the tooling to support this is useful.
  • With a good set of tests, prevents a whole class of errors caused by haste/impatience/divergent dev envs/etc.
  • Also worth mentioning - pipelines are something of an afterthought
  • Early this year, I demonstrated how to use Chef to configure Jenkins to run cookbook tests. This demonstrated some of the things I’m using today, but it was pretty rough. It was already due for an update two weeks after it was published (thanks to a new Jenkins cookbook), and I haven’t gone back to it yet…
  • Meanwhile, Eric Helgeson wrote a great post (with example cookbook) showing how he was using Jenkins. This includes groovy scripts for configuring authentication, and use of the Jenkins DSL plugin (which we’ll come to later). This motivated me to have another crack at the problem.
  • Add slides with examples of each
  • This needs to be a better way to solve this, but it wasn’t immediately apparent and pragmatism triumphed.
  • Idempotent? Well, you’ll get the same result but it will run every time…
  • Screenshot
  • If you’ve used these tools, you’ll know that foodcritic is very fast, chefspec is relatively fast, and kitchen tests are relatively slow. If your chefspec tests fail, you won’t even bother running Kitchen. Only if everything passes will you publish that commit to the Chef server.
  • Screenshot
  • Why not use kitchen parallel runner? Documented as intended for interactive use. Hard to read interleaved output.
  • What’s an artifact? For compiled languages, a build step compiles the source code, the resulting artifact is passed to subsequent jobs. In my pipeline, the primary artifact is Berksfile.lock
  • Others? Build Graph(?), Build Flow DSL (?), etc
  • Subjects for a later talk…
  • Sharing useful nuggets makes it easier for others to get started and contribute. Special thanks (again) to Eric Hegelson for this.
  • Add contact details