ci, cd and jenkins 2

61
CI, CD and Jenkins 2

Upload: pei-tang-huang

Post on 14-Apr-2017

637 views

Category:

Software


1 download

TRANSCRIPT

Page 1: CI, CD and Jenkins 2

CI,CDandJenkins2

Page 2: CI, CD and Jenkins 2

WhoAmI?

[email protected]• Youwillfindmehere

https://github.com/tan9

http://stackoverflow.com/users/3440376/tan9

• AnexperiencedCIadaptor• Hudson:Mid2009– February2011• Jenkins: February2011– present

2

Page 3: CI, CD and Jenkins 2

BeforeWe Get Started…

• Jointhechannel:http://bit.do/jenkins-training• Ordirectlink:https://gitter.im/tan9/jenkins-training

• SigninusingyourGitHub account• Orsignuprightnow!

3

Page 4: CI, CD and Jenkins 2

SilverBulletsforSoftwareQuality?

4

Page 5: CI, CD and Jenkins 2

5ByCourtesyoftheNavalSurfaceWarfareCenter,Dahlgren,VA.,1988.- U.S.NavalHistoricalCenterOnlineLibraryPhotographNH96566-KN,PublicDomain,https://commons.wikimedia.org/w/index.php?curid=165211

Page 6: CI, CD and Jenkins 2

6

Page 7: CI, CD and Jenkins 2

DevOps

7Imageby Rajiv.Pant derivativework: Wylve / CCBY3.0https://commons.wikimedia.org/wiki/File:Devops.svg

Page 8: CI, CD and Jenkins 2

ChatOps

8ImagefromGithub Hubot website:https://hubot.github.com/

Page 9: CI, CD and Jenkins 2

ImmutableInfrastructure

9Josha Stella,ImmutableInfrastructure:Considerations fortheCloudandDistributed Systems,2016,O’Reillyhttps://fugue.co/assets/docs/Immutable_Infrastructure_Fugue.pdf

Page 10: CI, CD and Jenkins 2

ContinuousIntegration

10

Page 11: CI, CD and Jenkins 2

Failfast andcheap.Failoften.Failinawaythatdoesn’tkillyou.

- SethGodin

11

Page 12: CI, CD and Jenkins 2

12https://commons.wikimedia.org/wiki/File:Hsiung_Feng_III_Anti-Ship_Missile_Display_in_Chengkungling_20111009a.jpg

Page 13: CI, CD and Jenkins 2

ContinuousIntegrationisthepracticeofmergingalldeveloper workingcopies

toasharedmainlineseveraltimesaday.

13http://en.wikipedia.org/wiki/Continuous_integration

Page 14: CI, CD and Jenkins 2

ContinuousWhat?

• Build• Test

• Unittests,integrationtests…

• Analysis• Feedback• Publish• Deploy• ...mosttediousthings!

14

Page 15: CI, CD and Jenkins 2

WhatToBeIntegrated?

• People• Code• Environment• Report• Thought• ...everythingvaluable!

15

Page 16: CI, CD and Jenkins 2

16WhyDevelopers<3CI:AGuidetoLovingContinuousIntegrationbyRebelLabs,2013http://zeroturnaround.com/rebellabs/rebel-labs-report-why-devs-love-ci-a-guide-to-loving-continuous-integration/

OR NOTIFY?

Page 17: CI, CD and Jenkins 2

CIPractices

• Maintainasinglesourcerepository• Automatethebuild• Makeyourbuildself-testing• Everycommitshouldbuildonanintegrationmachine• Keepthebuildfast• Testinacloneoftheproductionenvironment• Makeiteasyforanyonetogetthelatestexecutable• Everyonecanseewhat’shappening• Automatedeployment

ContinuousIntegration|ThoughtWorkshttps://www.thoughtworks.com/continuous-integration

17

Page 18: CI, CD and Jenkins 2

PowerTools

18WhyDevelopers<3CI:AGuidetoLovingContinuousIntegrationbyRebelLabs,2013http://zeroturnaround.com/rebellabs/rebel-labs-report-why-devs-love-ci-a-guide-to-loving-continuous-integration/

CI Servers Build Automation Tools Artifact Repositories Test Frameworks Code Analysis

Page 19: CI, CD and Jenkins 2

TeamResponsibilities

• Checkinfrequently• Don’tcheckinbrokencode• Don’tcheckinuntestedcode• Don’tcheckinwhenthebuildisbroken• Don’tgohomeaftercheckinginuntilthesystembuilds

19ContinuousIntegration|ThoughtWorkshttps://www.thoughtworks.com/continuous-integration

Page 20: CI, CD and Jenkins 2

20PaulM.Duvall etal,ContinuousIntegration:ImprovingSoftwareQualityandReducingRisk,2007,Addison-Wesley

Page 21: CI, CD and Jenkins 2

ContinuousDelivery

21

Page 22: CI, CD and Jenkins 2

Pipeline

22PragmaticContinuousDeliverywithJenkins,NexusandLiveRebel,2012http://zeroturnaround.com/rebellabs/zt-labs-tutorial-pragmatic-continuous-delivery-with-jenkins-nexus-and-liverebel/

Page 23: CI, CD and Jenkins 2

ContinuousDeliveryProcess

23ContinuousDeliveryprocessdiagrambyGrégoire Détrez,originalbyJezHumble//CCBY-SA4.0https://commons.wikimedia.org/wiki/File:Continuous_Delivery_process_diagram.svg

Page 24: CI, CD and Jenkins 2

HowAutomatedSurveyby

24PragmaticContinuousDeliverywithJenkins,NexusandLiveRebel,2012http://zeroturnaround.com/rebellabs/zt-labs-tutorial-pragmatic-continuous-delivery-with-jenkins-nexus-and-liverebel/

Page 25: CI, CD and Jenkins 2

ThoughtWorks®TechnologyRadar

25ThoughtWorks®Techonlogy RaderApril‘16https://www.thoughtworks.com/radar

Page 26: CI, CD and Jenkins 2

JenkinsTheButlerwithBowtie.

26

Page 27: CI, CD and Jenkins 2

PersonalInformation

• BabyofKohsuke Kawaguchi( )• InapastlifenamedHudson

27

Page 28: CI, CD and Jenkins 2

CIServerUsageSurveyby

28JavaToolsandTechnologiesLandscapeReport2016https://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-2016/

Page 29: CI, CD and Jenkins 2

Popularity(asof2016/06)

• TotalJenkinsinstallation

136,078• Totalnodes:

464,273⇒ 3.41nodesperinstallation

• Totaljobs8,858,054⇒ 65.56jobsperinstallation

29Jenkinsinfra-statisticshttp://stats.jenkins.io/jenkins-stats/

Page 30: CI, CD and Jenkins 2

Terminology

Term Description

Job/Project Runnabletasksthatarecontrolled/monitoredbyJenkins.

Build ResultofonerunofaProject.

Artifact

Slave Slavesarecomputersthataresetuptobuildprojectsforamaster.

Node RefertoallmachinethatarepartofJenkinsgrid,slavesandmaster.

Executor SeparatedstreamofbuildstoberunonNodeinparallel.

Workspace DisposabledirectoryonNodeusedasaworkingdirectoryforbuilding.

Publisher Partofthebuildprocessotherthancompilation.Apublishermayreport stable or unstable resultdependingontheresultofitsprocessing.

30

Page 31: CI, CD and Jenkins 2

BuildStatus

• StableBuild• Abuildisstableifitwasbuiltsuccessfullyandnopublisherreportsitasunstable.

• UnstableBuild• Abuildisunstableifitwasbuiltsuccessfullyandoneormorepublishersreportitunstable.

• FailedBuild• Abuildisbrokenifitfailedduringbuilding.Thatis,itisnotsuccessful.

31

Page 32: CI, CD and Jenkins 2

RunningJenkins

• Download• https://jenkins.io/

• Setenvironmentvariable(optional)

(defaultpath:~/.jenkins)• Run

32

java -jar jenkins.war [--httpPort=8080]

StartingandAccessingJenkinshttps://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins

JENKINS_HOME=/home/to/jenkins

Page 33: CI, CD and Jenkins 2

33

...Jul 27, 2016 4:59:14 PM jenkins.install.SetupWizard initINFO:

***************************************************************************************************************************************************************************************

Jenkins initial setup is required. An admin user has beencreated and a password generated.Please use the following password to proceed to installation:

9fa65e05a58c4e9c8e6fc4288dfb6c32

This may also be found at:/home/to/jenkins/secrets/initialAdminPassword

***************************************************************************************************************************************************************************************

...

Page 34: CI, CD and Jenkins 2

34

Page 35: CI, CD and Jenkins 2

35

Page 36: CI, CD and Jenkins 2

36

Page 37: CI, CD and Jenkins 2

37

Page 38: CI, CD and Jenkins 2

FreestyleProjectConfiguration

• SourceCodeManagement• BuildTriggers• BuildEnvironment• Build• Post-BuildActions

38

Page 39: CI, CD and Jenkins 2

MavenProjectConfiguration

• SourceCodeManagement• BuildTriggers• BuildEnvironment• Build

• PreSteps• Build• PostSteps• BuildSettings

• Post-BuildActions

39

Page 40: CI, CD and Jenkins 2

MultiConfiguration ProjectConfiguration• SourceCodeManagement• BuildTriggers• ConfigurationMatrix• BuildEnvironment• Build• Post-BuildActions

40

Page 41: CI, CD and Jenkins 2

WorkBehindProxy

41

Page 42: CI, CD and Jenkins 2

JenkinsGrid

42

Page 43: CI, CD and Jenkins 2

JenkinsMaster/SlaveMode

• Distributetheworkload• Providedifferentenvironmentsneededforbuilds/tests/deployments

43

Page 44: CI, CD and Jenkins 2

AgentLaunchMethods

• ViaJavaWebStart• Theagentneednotbereachablefromthemaster.

• Viaexecutionofcommandonthemaster• ViaSSHforagentsonUnixmachines

• Theslaveneedstobereachablefromthemaster,andyouwillhavetosupplyanaccountthatcanloginonthetargetmachine.

• ControlthisWindowsslaveasaWindowsservice• StartsaWindowsslavebyaremotemanagementfacilitybuiltintoWindows.

44

Page 45: CI, CD and Jenkins 2

LabelingNodes

• Groupingnodesby• O.S.:windows,linux,macos…• Architecture:x86,x64…• Capability:docker,jboss-eap…• What’smeaningfultoyou

• RestrictprojectrunnodebyLabelExpression

45

postgres && !vm && (linux || freebsd)

Page 46: CI, CD and Jenkins 2

JenkinsPipeline

46

Page 47: CI, CD and Jenkins 2

PipelineScript

47

node {// Mark the code checkout 'stage'....stage 'Checkout'

// Get some code from a GitHub repositorygit url: 'https://github.com/jglick/simple-maven-project-with-tests.git'

// Get the maven tool.// ** NOTE: This 'M3' maven tool must be configured// ** in the global configuration.def mvnHome = tool 'M3'

// Mark the code build 'stage'....stage 'Build'// Run the maven buildsh "${mvnHome}/bin/mvn -Dmaven.test.failure.ignore clean package"step([$class: 'JUnitResultArchiver',

testResults: '**/target/surefire-reports/TEST-*.xml'])}

Page 48: CI, CD and Jenkins 2

48

Page 49: CI, CD and Jenkins 2

MustHavePlugins

49

testng-plugin (5066)aw

s-java-sdk (5138)em

beddable-build-status (5324)publish-over-ftp (5326)global-build-stats (5343)saferestart (5380)port-allocator (5450)dynam

icparameter (5614)

emailext-tem

plate (5631)text-finder (5684)scp (5816)job-dsl (5847)jackson2-api (5900)next-build-num

ber (5922)flexible-publish (5936)join (6047)delivery-pipeline-plugin (6067)xcode-plugin (6075)extra-colum

ns (6075)chucknorris (6116)em

ma (6143)

configurationslicing (6146)job-im

port-plugin (6147)build-blocker-plugin (6152)buildgraph-view

(6173)backup (6220)description-setter (6230)bitbucket (6236)build-user-vars-plugin (6264)python (6304)groovy-postbuild (6799)docker-com

mons (6850)

ghprb (6914)nested-view

(6977)pow

ershell (6992)dry (7094)m

2release (7118)jquery-ui (7231)m

ask-passwords (7276)

performance (7418)

authentication-tokens (7471)m

onitoring (7511)plot (7537)github-oauth (7579)view

-job-filters (7587)copy-to-slave (7604)throttle-concurrents (7690)jacoco (7815)postbuildscript (7821)artifactdeployer (7888)artifactory (7932)gitlab-plugin (8091)sim

ple-theme-plugin (8525)

nodejs (8529)extended-choice-param

eter (8664)nodelabelparam

eter (8710)build-flow

-plugin (8791)scriptler (8800)jira (9035)build-m

onitor-plugin (9296)analysis-collector (9666)log-parser (9858)m

ercurial (10026)config-file-provider (10120)findbugs (10566)disk-usage (10583)prom

oted-builds (10804)deploy (10885)groovy (11094)git-param

eter (11173)w

arnings (11288)thinBackup (11411)jenkins-m

ultijob-plugin (11441)pm

d (11451)postbuild-task (11594)build-nam

e-setter (12007)violations (12025)ruby-runtim

e (12054)m

ultiple-scms (12256)

rebuild (13156)m

sbuild (13724)ansicolor (13728)slack (14224)xunit (14282)checkstyle (14570)cobertura (15036)ssh (15256)role-strategy (15568)active-directory (16103)jobConfigHistory (17002)credentials-binding (17160)sonar (17959)dashboard-view

(18311)publish-over-ssh (20323)build-pipeline-plugin (20789)htm

lpublisher (21602)ssh-agent (21616)github-organization-folder (22666)github-branch-source (23954)tim

estamper (24135)

greenballs (25435)copyartifact (25447)build-tim

eout (26543)gradle (26968)conditional-buildstep (27137)pipeline-input-step (28677)pipeline-stage-view

(28748)pipeline-build-step (28748)pipeline-stage-step (28757)pipeline-rest-api (28915)w

orkflow-m

ultibranch (28923)m

omentjs (29860)

handlebars (29895)w

orkflow-aggregator (29983)

run-condition (30104)branch-api (30341)w

orkflow-cps-global-lib (30519)

analysis-core (31396)w

orkflow-durable-task-step (31586)

ws-cleanup (31678)

workflow

-basic-steps (32051)w

orkflow-job (32349)

workflow

-cps (32438)ace-editor (32579)jquery-detached (33204)w

orkflow-support (33697)

workflow

-api (34186)envinject (34317)cloudbees-folder (35981)durable-task (36386)jquery (38276)w

orkflow-scm

-step (38884)github (40406)git-server (40803)github-api (43238)structs (43239)plain-credentials (44323)param

eterized-trigger (46900)em

ail-ext (50123)icon-shim

(52730)w

orkflow-step-api (56279)

mapdb-api (73081)

token-macro (88146)

git (89345)git-client (92022)scm

-api (104976)script-security (114827)cvs (116614)translation (119714)junit (121377)m

atrix-project (125657)w

indows-slaves (126388)

antisamy-m

arkup-formatter (126489)

maven-plugin (127956)

subversion (128710)m

atrix-auth (129015)ldap (131841)ssh-slaves (132146)pam

-auth (132151)ant (132412)external-m

onitor-job (132612)ssh-credentials (132621)credentials (132919)javadoc (133300)m

ailer (133547)

Page 50: CI, CD and Jenkins 2

s/green/blue/g

• It'snotforcolorblindusers.• It'sallabout(influencedby):

• GreenBallsPlugin• https://wiki.jenkins-ci.org/display/JENKINS/Green+Balls

50

青Cyan #00FFFF

“WhydoesJenkinshaveblueballs?” on2012-03-13by R.TylerCroyhttps://jenkins.io/blog/2012/03/13/why-does-jenkins-have-blue-balls/

Page 51: CI, CD and Jenkins 2

• Gravatar - GloballyRecognizedAvatar• Registeryourownavatar

• athttps://en.gravatar.com/

• Makeiteasiertoidentifyone

51

Page 52: CI, CD and Jenkins 2

StaticCodeAnalyses

52

• Checkstyle• DRY• FindBugs• PMD• CompilerWarnings• TaskScanner

• TODO,FIXME,XXX...

Page 53: CI, CD and Jenkins 2

PluginsAvailable

• FindBugs Plugin• Checkstyle Plugin• PMDPlugin• DRYPlugin• JaCoCo Plugin• WarningsPlugin

53

Page 54: CI, CD and Jenkins 2

JobConfigurationHistory

• Recordeverysinglechange• Savesacopyoftheconfigurationfileofajob(config.xml)foreverychangemade.

54

Page 55: CI, CD and Jenkins 2

SCMSyncConfiguration

• Keepsync'ed configurationswithaSCMrepository.• Trackchanges(andauthor)madeoneveryfilewithcommitmessages.

55

Page 56: CI, CD and Jenkins 2

ConfigurationSlicing

56

• Performmassconfigurationofselectprojectproperties.

Page 57: CI, CD and Jenkins 2

DiskUsage

• Keepwatching!

57

Page 58: CI, CD and Jenkins 2

FutureofJenkins

58

Page 59: CI, CD and Jenkins 2

59

Page 60: CI, CD and Jenkins 2

ProjectBlueOcean

60

Page 61: CI, CD and Jenkins 2

YourTurnNow!

61