Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you...

47
©2010 CloudBees, Inc. All Rights Reserved Large-Scale Automation with Jenkins Kohsuke Kawaguchi / [email protected] / @kohsukekawa Architect, CloudBees, Inc.

Transcript of Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you...

Page 1: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Large-Scale Automation with JenkinsKohsuke Kawaguchi / [email protected] / @kohsukekawaArchitect, CloudBees, Inc.

Page 2: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

2©2010 CloudBees, Inc. All Rights Reserved

Have you met Jenkins?http://jenkins-ci.org/

Page 3: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

3©2010 CloudBees, Inc. All Rights Reserved

x 64,000

Page 4: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

4©2010 CloudBees, Inc. All Rights Reserved

Page 5: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

5©2010 CloudBees, Inc. All Rights Reserved

x 700

Page 6: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

6©2010 CloudBees, Inc. All Rights Reserved

Context

http://www.flickr.com/photos/spidermandragon5/2922128673/

Page 7: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

7©2010 CloudBees, Inc. All Rights Reserved

Workflow!

Page 8: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

8©2010 CloudBees, Inc. All Rights Reserved

Page 9: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

9©2010 CloudBees, Inc. All Rights Reserved

Page 10: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

10©2010 CloudBees, Inc. All Rights Reserved

Parameterized Builds

• Plain jobs can be thought of like a procedure without any input

• Ability to pass parameters make it more useful

void buildAcmeLibrary() { … }

void buildAcmeLibrary(targetPlatform) { … }

Page 11: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

11©2010 CloudBees, Inc. All Rights Reserved

Three Things You Need To Do

• #1: Define Parameters

Lots of different parameter types

Page 12: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

12©2010 CloudBees, Inc. All Rights Reserved

Three Things You Need To Do

• #2: Refer to parameter values

– As variable expansions: ${Browser}

– As environment variables from your builds

– Some parameter types expose data in different ways

– File parameter

Page 13: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

13©2010 CloudBees, Inc. All Rights Reserved

Three Things You Need To Do

• #3: Specify actual values when you run

Page 14: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

14©2010 CloudBees, Inc. All Rights Reserved

Parameterized Trigger Plugin

• Call other jobs (with parameters)

– Wait for their completions (optional)

Foo

Sub1 Sub2 Sub3

Foo

Sub1

Sub2

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

Page 15: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

15©2010 CloudBees, Inc. All Rights Reserved

Other Simple Choreography Tools

• Join Pluginhttps://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin

Page 16: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

16©2010 CloudBees, Inc. All Rights Reserved

When Jobs Start Working Together…

• Copy Artifact Plugin

– Copy artifacts into a workspace

– By using various criteria

https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin

acme-build #15

foo.jar

acme-test #24

foo.jar

Page 17: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

17©2010 CloudBees, Inc. All Rights Reserved

acme-build #10acme-build #11

acme-build #12acme-build #13

acme-build #14

Copy Artifact vs External Repository

• Almost as if artifacts are versioned

acme-build #15

foo.jar

Last stable build

Last saved build

Page 18: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

18©2010 CloudBees, Inc. All Rights Reserved

Labeling Builds Is Useful

• Especially when labels have semantics

acme-build #10acme-build #11

acme-build #12acme-build #13

acme-build #14acme-build #15

foo.jar

Last stable build

Signed off to QA

Deployed to production

Page 19: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

19©2010 CloudBees, Inc. All Rights Reserved

Labeling Builds Is Useful

• More so when you automate them

• Take “Signed off to QA” label for example

acme-build #12

acme-devtest #15

acme-findbugs #22

acme-devtest #15

acme-findbugs #22

Signed off to QA

foo.jar

Page 20: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

20©2010 CloudBees, Inc. All Rights Reserved

Introducing Promoted Builds Plugin

• Promotion = act of giving a build a label

• You specify:

– Promotion criteria

– what happens after promotion

• Label is a nice hand-off between teams

– It’s like sausage making process

https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin

Page 21: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Demo

Page 22: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

22©2010 CloudBees, Inc. All Rights Reserved

Maven Repository Plugin

• Virtual Maven repository

– Expose artifacts from specific build

– And its upstream builds

https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Maven+Repository+Server

Page 23: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

23©2010 CloudBees, Inc. All Rights Reserved

Challenge: visualization

http://www.flickr.com/photos/andresmusta/7990193487

Page 24: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

24©2010 CloudBees, Inc. All Rights Reserved

Challenge: Visualization

• Edge traversal breaks down on large workflow

Page 25: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

25©2010 CloudBees, Inc. All Rights Reserved

Dependency Graph https://wiki.jenkins-ci.org/display/JENKINS/Dependency+Graph+View+Plugin

Page 26: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

26©2010 CloudBees, Inc. All Rights Reserved

Build Pipeline Pluginhttps://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin

• It shows how far each change has gone

Page 27: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Demo

Page 28: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

28©2010 CloudBees, Inc. All Rights Reserved

Fingerprint

• Yet another angle to look at data

• Think of it as a lifelog for a blob

Air travel JenkinsAirline check-in/TSA/immigration

Jobs and workflow

My going through immigration

Build #13

My travel experience Fingerprint view

Page 29: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

29©2010 CloudBees, Inc. All Rights Reserved

Fingerprint: Mechanism

• MD5 checksum of a file

– Recorded against builds that it appeared

– (And actions that were taken)acme-build #15

MD5=604e7e07

acme-test #13

MD5=604e7e07

Page 30: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

30©2010 CloudBees, Inc. All Rights Reserved

Fingerprint: Why?

• Track down where it came from

– My component integrates to product XYZ, and a bug was reported against XYZ 3.0.5. Which build of the component did it contain?

• Cross-correlate jobs that aren’t directly related

Page 31: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

31©2010 CloudBees, Inc. All Rights Reserved

Next Step in Workflow

Aggregation of results

Aggregation of definitions

?

Page 32: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

32©2010 CloudBees, Inc. All Rights Reserved

Build Flow Plugin

• Groovy DSL for kicking builds

– High-level primitives

– Ability to define abstractions

b = build(“acme-build”)guard {

parallel ({ build(“acme-test1”,

param1:b.number) },{ build(“acme-test2”,

param1:b.number) })

} rescue {build(“acme-teardown”)

}

https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin

Page 33: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Demo

Page 34: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

34©2010 CloudBees, Inc. All Rights Reserved

Jenkow Plugin

• Embed BPMN workflow engine in Jenkins

– Timeout, fork, join, …

• Workflow is version controlled in Git

– Push to Jenkins to load them up

https://wiki.jenkins-ci.org/display/JENKINS/Jenkow+Plugin

Page 35: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Demo

Page 36: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

36©2010 CloudBees, Inc. All Rights Reserved

Next Step in Workflow

Choreography defined in one place

Everything defined in one place

?

Page 37: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

37©2010 CloudBees, Inc. All Rights Reserved

Job DSL Plugin

• Groovy DSL for defining jobsdef project = "jenkinsci/jenkins"def branchApi = new URL("https://api.github.com/repos/${project}/branches")def branches = new JsonSlurper().parse(branchApi.newReader())branches.each { b -> job { name "${project}-${b.name}".replaceAll('/','-') scm { git("git://github.com/${project}.git", b.name) } steps { maven("install") } }}

https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin

Page 38: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

38©2010 CloudBees, Inc. All Rights Reserved

Or More Likely…

• Take Existing Job, Make Adjustmentsdef project = "jenkinsci/jenkins"def branchApi = new URL("https://api.github.com/repos/${project}/branches")def branches = new JsonSlurper().parse(branchApi.newReader())branches.each { b -> job { using "jenkins-build" name "${project}-${b.name}".replaceAll('/','-') scm { git("git://github.com/${project}.git", b.name) } }}

Page 39: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

39©2010 CloudBees, Inc. All Rights Reserved

Job DSL Plugin

• You can go down to XML definitions

• The program itself executes as Jenkins job

– Control over when it executes

– Store definitions in VCS

Page 40: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

40©2010 CloudBees, Inc. All Rights Reserved

Or just a bit of Perl/Python/Ruby scripts

• Programmatically CRUD jobs

$ ssh jenkins get-job foo \| sed -e 's/old.gitserver.com/new.gitserver.com/g’ \| ssh jenkins update-job foo

Page 41: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

41©2010 CloudBees, Inc. All Rights Reserved

Templates (in Jenkins Enterprise by CloudBees)

• Share some traits with Job DSL

– Define job once, generate many variations

– Update definition, and reflect it everywhere

• But different

– Templates are defined in GUI, not in a program

– Individual variations are manually updated by users

http://www.cloudbees.com/jenkins-enterprise-by-cloudbees-overview.cb

Page 42: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

42©2010 CloudBees, Inc. All Rights Reserved

Conclusion

• Lots of useful building blocks for automating even more

– That means many people are doing this

• Take your automation to the next level

Page 43: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

43©2010 CloudBees, Inc. All Rights Reserved

Multi-Configuration Project

• You often do the same thing with slight variations

– Compile C++ code for different platforms

– Test with different browsers

– Or more generally, think of it asfor (x in [a,b,c]) { for (y in [d,e,f]) { doSomethingWith(x,y,...); }}

Page 44: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

44©2010 CloudBees, Inc. All Rights Reserved

Model

• Define axes

– One axis ≈ one for loop

• Choose from pre-defined types of Axis

– Generic axis: arbitrary values exposed as environment variables

– Slave axis: pick slaves by their names or their labels

– e.g., linux, solaris, and windows

– JDK axis

Page 45: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

45©2010 CloudBees, Inc. All Rights Reserved

Multi-Configuration Project Gimmicks

• Filtering

– Otherwise combinations increase exponentially

– Not all combinations make sense

– Use boolean expression to trim down the size

– Or tell Jenkins to cut the workload to N%

– Jenkins will thin out the combinations by itself

(label==“windows”).implies(browser==“iexplore”) &&(label==“mac”).implies(browser==“safari”)

Page 46: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

©2010 CloudBees, Inc. All Rights Reserved

Demo

Page 47: Large-Scale Automation with Jenkins€¦ · ©2010 CloudBees, Inc. All Rights Reserved 2 Have you met Jenkins?

©2010 CloudBees, Inc. All Rights Reserved

47©2010 CloudBees, Inc. All Rights Reserved