CLUG 2014-10 - Cookbook CI with Jenkins

40
Cookbook CI with Jenkins Part 1

description

An overview of how I'm using Chef to automate Jenkins to test Chef cookbooks.

Transcript of CLUG 2014-10 - Cookbook CI with Jenkins

Page 1: CLUG 2014-10 - Cookbook CI with Jenkins

Cookbook CI with Jenkins

Part 1

Page 2: CLUG 2014-10 - Cookbook CI with Jenkins

Who Am I?

• "zts" most places on the internet

• Mostly Ops, Background, Mostly

• Co-founder Elastera

Page 3: CLUG 2014-10 - Cookbook CI with Jenkins

Who Are You?

Page 4: CLUG 2014-10 - Cookbook CI with Jenkins

Cookbook Testing

• foodcritic, chefspec, test-kitchen

• Get things right

• Keep things right

Page 5: CLUG 2014-10 - Cookbook CI with Jenkins
Page 6: CLUG 2014-10 - Cookbook CI with Jenkins

CI Servers

• System for running actions on every commit

• Identify problems early

• Jenkins, GoCD, TravisCI, Wercker, etc

Page 7: CLUG 2014-10 - Cookbook CI with Jenkins

Why Jenkins?

• Mature

• Extensible

• Good Chef Cookbook

• Free

Page 8: CLUG 2014-10 - Cookbook CI with Jenkins

Why Not Jenkins?

• TMTOWTDI

• XML, so much XML

• Automation is not a joy

Page 9: CLUG 2014-10 - Cookbook CI with Jenkins

Jenkins Cookbook

• Install Jenkins & Plugins

• Create jobs

• Run commands and scripts

Page 10: CLUG 2014-10 - Cookbook CI with Jenkins

Previously…

• Cooking With Jenkins

• ...and Kitchen, and Docker

Page 12: CLUG 2014-10 - Cookbook CI with Jenkins

Basic Configuration

• Install Plugins

• Configure Plugins

• Configure Jenkins

Page 13: CLUG 2014-10 - Cookbook CI with Jenkins

Installing Plugins

• Idempotent

• No dependency resolution

• Restart may be required

Page 14: CLUG 2014-10 - Cookbook CI with Jenkins

Plugin Configuration

• XML :(

• ...containing module version strings :((

• Hold nose and use cookbook_file

Page 15: CLUG 2014-10 - Cookbook CI with Jenkins

Jenkins Configuration

Page 16: CLUG 2014-10 - Cookbook CI with Jenkins

Creating Jobs

• jenkins_job

• Job DSL plugin

• Jenkins Job Builder

Page 17: CLUG 2014-10 - Cookbook CI with Jenkins
Page 18: CLUG 2014-10 - Cookbook CI with Jenkins
Page 19: CLUG 2014-10 - Cookbook CI with Jenkins

Pipeline

• Foodcritic

• Chefspec

• Kitchen

• Publish

Page 20: CLUG 2014-10 - Cookbook CI with Jenkins

And after publish?

• That's why this is Part 1...

Page 21: CLUG 2014-10 - Cookbook CI with Jenkins

Foodcritic

• Warnings plugin :)

• XML config :(

Page 22: CLUG 2014-10 - Cookbook CI with Jenkins
Page 23: CLUG 2014-10 - Cookbook CI with Jenkins
Page 24: CLUG 2014-10 - Cookbook CI with Jenkins

Chefspec

• yarjuf gem

• Publish JUnit test result report

Page 25: CLUG 2014-10 - Cookbook CI with Jenkins
Page 26: CLUG 2014-10 - Cookbook CI with Jenkins
Page 27: CLUG 2014-10 - Cookbook CI with Jenkins

Test Kitchen

• kitchen-docker

• Matrix jobs

• EnvInject and AnsiColor plugins

Page 28: CLUG 2014-10 - Cookbook CI with Jenkins
Page 29: CLUG 2014-10 - Cookbook CI with Jenkins

Berkshelf

• upload to Chef server

• record version as artifact

Page 30: CLUG 2014-10 - Cookbook CI with Jenkins
Page 31: CLUG 2014-10 - Cookbook CI with Jenkins

Berkshelf

• curl -s https://jenkins.example/job/berks-upload/lastSuccessfulBuild/artifact/VERSION

Page 32: CLUG 2014-10 - Cookbook CI with Jenkins

Gluing it together

• Publish Artifact

• Copy Artifact

• Build Pipeline

Page 33: CLUG 2014-10 - Cookbook CI with Jenkins

Pipelines

• Build Pipeline plugin

• Build Graph View plugin

• Build Flow DSL

• ...and more

Page 34: CLUG 2014-10 - Cookbook CI with Jenkins

Build Pipeline

Page 35: CLUG 2014-10 - Cookbook CI with Jenkins

What's Missing?

• JUnit output from serverspec

• View most recent run of all pipelines

• Notifications

Page 36: CLUG 2014-10 - Cookbook CI with Jenkins

Not the whole story...

• Testing a set of cookbooks

• Testing multiple nodes

• Promoting releases

Page 37: CLUG 2014-10 - Cookbook CI with Jenkins

Summary

• Not that hard to get started

• Immediately valuable

• Share your work!

Page 38: CLUG 2014-10 - Cookbook CI with Jenkins

Questions?

Page 39: CLUG 2014-10 - Cookbook CI with Jenkins

Resources

http://www.cryptocracy.com/blog/2014/01/03/cooking-with-jenkins-test-kitchen-and-docker/https://erichelgeson.github.io/blog/2014/05/10/automating-your-automation-federated-jenkins-with-chef/http://atomic-penguin.github.io/blog/2014/05/16/stupid-jenkins-tricks-part-2-cookbook-pipelines/http://www.hurryupandwait.io/blog/using-git-to-version-stamp-chef-artifacts

https://github.com/jenkinsci/job-dsl-plugin/wikihttps://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Pluginhttps://wiki.jenkins-ci.org/display/JENKINS/Building+a+matrix+project

Page 40: CLUG 2014-10 - Cookbook CI with Jenkins

Thankyou

Twitter: @zts

email: [email protected]