63
Continuous Integration

Jenkins slides reordered - census.gov · • Developers commit code to a shared repository on a regular basis. • Version control system is being monitored. When a commit is detected,

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Continuous Integration

ContinuousIntegration• WhatisContinuousIntegration?• Whydoweneedit?• DifferentphasesofadoptingContinuousIntegration

• Developerscommitcodetoasharedrepositoryonaregularbasis.

• Versioncontrolsystemisbeingmonitored.Whenacommitisdetected,abuildwillbetriggeredautomatically.

• Ifthebuildisnotgreen,developerswillbenotifiedimmediately.

WhatisContinuousIntegration?

WhydoweneedContinuousIntegration?

• Detectproblemsorbugs,asearlyaspossible,inthedevelopmentlifecycle.

• Sincetheentirecodebaseisintegrated,builtandtestedconstantly,thepotentialbugsanderrorsarecaughtearlierinthelifecyclewhichresultsinbetterqualitysoftware.

DifferentstagesofadoptingContinuousIntegration

Fewcommits

Stage1:

• Nobuildservers.

• Developerscommitonaregularbasis.

• Changesareintegratedandtestedmanually.

• Fewerreleases.

Stage2:

Buildnightly

Buildandruntests

• Automatedbuildsarescheduledonaregularbasis.

• Buildscriptcompilestheapplicationandrunsasetofautomatedtests.

• Developersnowcommittheirchangesregularly.

• Buildserverswouldalerttheteammembersincaseofbuildfailure.

Stage3:

Triggeredatomically

Buildandruntests

• A buildistriggeredwhenevernewcodeiscommittedtothecentralrepository.

• Brokenbuildsareusuallytreatedasahighpriorityissueandarefixedquickly.

Stage4:

Triggeredatomically

Build,runcodequalityandcodecoveragemetricsalongwithtests

• Automatedcodequalityandcodecoveragemetricsarenowrunalongwithunitteststocontinuouslyevaluatethecodequality.

Isthecodecoverageincreasing?

Dowehavefewerandfewerbuildfailures?

Stage5:

Triggeredatomically

• AutomatedDeployment

Production

CI/CD Environment

_______________________________________________

ContinuousIntegrationContinuousDelivery

ContinuousDeployment

• ContinuousIntegrationThepracticeofmergingdevelopmentworkwiththemainbranchconstantly.

• ContinuousDeliveryContinualdeliveryofcodetoanenvironmentoncethecodeisreadytoship.Thiscouldbestagingorproduction.Theideaistheproductisdeliveredtoauserbase,whichcanbeQAsorcustomersforreviewandinspection.

• ContinuousDeploymentThedeploymentorreleaseofcodetoproductionassoonasitisready.

DevOps

__________________________________________________

Bestamigo
Typewritten Text
Bestamigo
Typewritten Text
Bestamigo
Typewritten Text
Bestamigo
Typewritten Text
Bestamigo
Typewritten Text
Deployment

HowtoimplementContinuousIntegration?

Non-hostedsolutions Hostedsolutions

ContinuousIntegrationisalsoamindset

• Fixingbrokenbuildsshouldbetreatedasahighpriorityissueforallteammembers.

• Thedeploymentprocessshouldbeautomated,withnomanualstepsinvolved.

• Allteammembersshouldfocusoncontributingtohigh-qualitytestsbecausetheconfidentialityoftheCIprocesshighlydependsonthequalityofthetests.

WhatisJenkins• Jenkinsisacontinuousintegrationandbuildserver.

• Itisusedtomanually,periodically,orautomaticallybuildsoftware

developmentprojects.

• ItisanopensourceContinuousIntegrationtoolwritteninJava.

• Jenkinsisusedbyteamsofalldifferentsizes,forprojectswithvarious

languages.

WhyJenkinsispopular• Easytouse

• Greatextensibility– Supportdifferentversioncontrolsystems

– Codequalitymetrics

– Buildnotifiers

– UIcustomization

• Jenkins’MasterandSlaveArchitecture• SomeImportantJenkins’Terminologies

Jenkins’MasterandSlaveArchitecture

Master:• Schedulebuildjobs.• Dispatchbuildstotheslavesforthe

actualjobexecution.• Monitortheslavesandrecordthe

buildresults.• Canalsoexecutebuildjobsdirectly.

Slave:• Executebuildjobsdispatchedby

themaster.

JenkinsUIOverview

InstallGITandGitHub plugin

InstallandConfigureMaven

WhatdoesMavendo?

• Mavendescribeshowthesoftwareisbuilt.• Mavendescribestheproject’sdependencies.

JavaBuildTools

ConfigureJenkinsforaMaven -basedproject

CreateaMaven -basedJenkinsproject

Run Maven-basedJenkinsproject

Mavenpom.xml file• Describethesoftwareprojectbeingbuilt,including

– Thedependenciesonotherexternalmodules.– Thedirectorystructures.– Therequiredplugins.– Thepredefinedtargetsforperformingcertaintaskssuchas

compilationandpackaging.

DifferentPhasesinMavenBuildLifecycle

validate Validatetheprojectiscorrectandallnecessaryinformationisavailable.compile Compilethesourcecodeoftheproject.test Testthecompiledsourcecodeusingasuitableunittestingframework.package Takethecompiledcodeandpackageitinitsdistributableformat.verify Runanychecksonresultsofintegrationteststoensurequalitycriteriaaremet.install Installthepackageintothelocalrepository,foruseasadependencyinother

projectslocally.deploy Copythefinalpackagetotheremoterepositoryforsharingwithother

developersandprojects.

MavenBuildPhases• Theselifecyclephasesareexecutedsequentiallytocompletethedefault

lifecycle.

• Wewanttospecifythemavenpackage command,thiscommandwouldexecuteeachdefaultlifecyclephaseinorderincludingvalidate,compile,test beforeexecutingpackage.

• Weonlyneedtocallthelastbuildphasetobeexecuted.

Jenkinscodequalitymetricsreport

Checkstyle isacodestaticanalysistooltohelpprogrammerstowriteJavacodethatadherestoacodingstandardsuchas

• Avoidingmultipleblanklines;• Removingunusedvariables;• Enforcingcorrectindentations;• …

Jenkins’supportforotherbuildsystems(Ant,Gradle andshellscripts)

ApacheAnt• Widely-usedandverywell-knownbuildscriptinglanguageforJava.• Flexible,extensible,relativelylow-levelscriptinglanguage.• AnAntbuildscriptismadeupofanumberoftargets,eachtarget

performsaparticularjobinthebuildprocess.

Gradle• Gradle isarelativelynewopensourcebuildtoolfortheJavaVirtualMachine.• BuildscriptsforGradle arewritteninaDomainSpecificLanguagebasedon

Groovy.• TheconcisenatureofGroovyscriptingletsyouwriteveryexpressivebuildscripts

withverylittlecode.

Build Scripts

Maven Build Script

\

Gradle Build Script

Ant Build Script Sample

InstallandconfigureTomcatasastagingenvironment

TomcatTomcatisanopen-sourcewebserverandprovidesa"pureJava”HTTPwebserverenvironmentinwhichJavacodecanrun.

• Installcopyartifact anddeploytocontainer plugins• Deployourapplicationtostagingenvironment

JenkinsBuildPipeline

BuildPipelinePlugin

ParallelJenkinsBuild

ContinuousDeliveryDeployourapptoproduction

Benefitsofacode-basedpipeline• Versioncontrol

• BestPractices

• Lesserror-proneexecutionofjobs

• Logic-basedexecutionofsteps

SampleJenkinsfile

Additionalautomation• SetupGitrepositorypolling

• Deploymenttoourtomcatservers

• Wewillsetuptasks to run in parallel

Steps• Step1:Configuresecurit groups for Tomcat servers and create key pairs.

• Step2:Provisioninstances to staging and productionenvironments.

• Step3:InstallandrunTomcatoncreatedinstances.

• Step4:FullyautomateourexistingJenkinspipeline.

IntroductiontoDistributedJenkinsBuilds

InstallJenkinsMasterintheCloud

JenkinsSlaveAgent

InstallJenkinsslavesinthecloudandformaJenkinscluster

ConcurrentBuildsonJenkinsClusterLabelJenkinsNodes

Build Orchestration: Jenkins _____________________________

• Continuous integration system • Enable automated build and test process • Can monitoring executions of externally‐run jobs, such as cron jobs and procmail jobs… • Dependency tracking, allowing file finger printing and tracking for example which build is using which version of jars… • Generates list of changes made to build from Subversion • Distributed build/test

• Jenkins is a build orchestration, CI software • building/testing software projects continuously • monitoring executions of externally‐run jobs

• FishEye allows you to extract information from your source code repository and display it in sophisticated reports. • Crucible allows you to request, perform and manage code reviews. • Subversion centralized version control system • Sonar is a quality management platform for analyzing and measuring source code quality.

CI/CD Pipeline: Functional Architecture

_______________________________________________

Version Control

Version

Control System

Code

Repository

Artifact Repository (Artifactory)

Build Management

(Maven)

Build

Automation

(Jenkins)

Test

Automation QA

(SonarCube)

Release

Orchestration

Deployment

Automation

Develop Pre-commit Tests

1

2 Commit code to Version Control

System 3 CI polls VCS

and creates Build 5

Automated Test Staging

UAT SAT

Security Scan Perf. & Load Testing

7

4 6

Release

8

Fail Fail Fail

Not approved

9

An Automated, Integrated and End to Ent CCRM

_______________________________________________

Git, GitLab, GitHub Enteprise, SVN…

Maven, Ant, Gradle

Nexsus, Artifactory

Jenkins…

Junit, Test NG, Cucumber, Selenium, JMeter, SoapUI, LoadRunner…

Release Management

Source Code Management

( Version Control)

Build Automation

CCRM

Test

Automation

Environment Configuration Management CI/CD