CI,	CD	and	Jenkins	2
Who	Am	I?
• beta@cht.com.tw
• You	will	find	me	here
https://github.com/tan9
http://stackoverflow.com/users/3440376/tan9
• An	experienced	CI	adaptor
• Hudson: Mid	2009	– February	2011
• Jenkins: February	2011	– present
2
Before	We Get Started…
• Join	the	channel:	http://bit.do/jenkins-training
• Or	direct	link:	https://gitter.im/tan9/jenkins-training
• Sign	in	using	your	GitHub account
• Or	sign	up	right	now!
3
Silver	Bullets	for	
Software	Quality?
4
5By	Courtesy	of	the	Naval	Surface	Warfare	Center,	Dahlgren,	VA.,	1988.	- U.S.	Naval	Historical	Center	Online	Library	
Photograph	NH	96566-KN,	Public	Domain,	https://commons.wikimedia.org/w/index.php?curid=165211
6
DevOps
7Image	by Rajiv.Pant derivative	work: Wylve / CC	BY	3.0
https://commons.wikimedia.org/wiki/File:Devops.svg
ChatOps
8Image	from	Github Hubot website:	https://hubot.github.com/
Immutable	Infrastructure
9Josha Stella,	Immutable	Infrastructure:	Considerations for	the	Cloud	and	Distributed Systems,	2016,	O’Reilly
https://fugue.co/assets/docs/Immutable_Infrastructure_Fugue.pdf
Continuous	Integration
10
Fail	fast and	cheap.
Fail	often.	Fail	in	a	
way	that	doesn’t	kill
you.
- Seth	Godin
11
12https://commons.wikimedia.org/wiki/File:Hsiung_Feng_III_Anti-Ship_Missile_Display_in_Chengkungling_20111009a.jpg
Continuous	Integration
is	the	practice	of		merging
all	developer working	copies
to	a	shared	mainline
several	times	a	day.
13http://en.wikipedia.org/wiki/Continuous_integration
Continuous	What?
• Build
• Test
• Unit	tests,	integration	tests…
• Analysis
• Feedback
• Publish
• Deploy
• ...	most	tedious	things!
14
What	To	Be	Integrated?
• People
• Code
• Environment
• Report
• Thought
• ...	everything	valuable!
15
16Why	Developers	<3	CI:	A	Guide	to	Loving	Continuous	Integration	by	Rebel	Labs,	2013
http://zeroturnaround.com/rebellabs/rebel-labs-report-why-devs-love-ci-a-guide-to-loving-continuous-integration/
OR NOTIFY?
CI	Practices
• Maintain	a	single	source	repository
• Automate	the	build
• Make	your	build	self-testing
• Every	commit	should	build	on	an	integration	machine
• Keep	the	build	fast
• Test	in	a	clone	of	the	production	environment
• Make	it	easy	for	anyone	to	get	the	latest	executable
• Everyone	can	see	what’s	happening
• Automate	deployment
Continuous	Integration	|	ThoughtWorks
https://www.thoughtworks.com/continuous-integration
17
Power	Tools
18Why	Developers	<3	CI:	A	Guide	to	Loving	Continuous	Integration	by	Rebel	Labs,	2013
http://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
Team	Responsibilities
• Check	in	frequently
• Don’t	check	in	broken	code
• Don’t	check	in	untested	code
• Don’t	check	in	when	the	build	is	broken
• Don’t	go	home	after	checking	in	until	the	system	
builds
19Continuous	Integration	|	ThoughtWorks
https://www.thoughtworks.com/continuous-integration
20Paul	M.	Duvall et	al,	Continuous	Integration:	Improving	Software	Quality	and	Reducing	Risk,	2007,	Addison-Wesley
Continuous	Delivery
21
Pipeline
22Pragmatic	Continuous	Delivery	with	Jenkins,	Nexus	and	LiveRebel,	2012
http://zeroturnaround.com/rebellabs/zt-labs-tutorial-pragmatic-continuous-delivery-with-jenkins-nexus-and-liverebel/
Continuous	Delivery	Process
23Continuous	Delivery	process	diagram	by	Grégoire Détrez,	original	by	Jez	Humble	//	CC	BY-SA	4.0
https://commons.wikimedia.org/wiki/File:Continuous_Delivery_process_diagram.svg
How	Automated	Survey	by
24Pragmatic	Continuous	Delivery	with	Jenkins,	Nexus	and	LiveRebel,	2012
http://zeroturnaround.com/rebellabs/zt-labs-tutorial-pragmatic-continuous-delivery-with-jenkins-nexus-and-liverebel/
ThoughtWorks®	Technology	Radar
25ThoughtWorks®	Techonlogy Rader	April	‘16
https://www.thoughtworks.com/radar
Jenkins
The	Butler	with	Bowtie.
26
Personal	Information
• Baby	of	Kohsuke Kawaguchi	( )
• In	a	past	life	named	Hudson
27
CI	Server	Usage	Survey	by
28Java	Tools	and	Technologies	Landscape	Report	2016
https://zeroturnaround.com/rebellabs/java-tools-and-technologies-landscape-2016/
Popularity	(as	of	2016/06)
• Total	Jenkins	installation
136,078
• Total	nodes:
464,273
3.41	nodes	per	installation
• Total	jobs
8,858,054
65.56	jobs	per	installation	
29Jenkins	infra-statistics
http://stats.jenkins.io/jenkins-stats/
Terminology
Term Description
Job/Project Runnable	tasks	that	are	controlled	/	monitored	by	Jenkins.
Build Result	of	one	run	of	a	Project.
Artifact
Slave Slaves	are	computers	that	are	set	up	to	build	projects	for	a	master.
Node Refer	to	all	machine	that	are	part	of	Jenkins	grid,	slaves	and	master.
Executor Separated	stream	of	builds	to	be	run	on	Node	in	parallel.
Workspace Disposable	directory	on	Node	used	as	a	working	directory	for	
building.
Publisher Part	of	the	build	process	other	than	compilation.	A	publisher	may	
report stable or unstable result	depending	on	the	result	of	its	
processing.
30
Build	Status
• Stable	Build
• A	build	is	stable	if	it	was	built	successfully	and	no	
publisher	reports	it	as	unstable.
• Unstable	Build
• A	build	is	unstable	if	it	was	built	successfully	and	one	or	
more	publishers	report	it	unstable.
• Failed	Build
• A	build	is	broken	if	it	failed	during	building.	That	is,	it	is	
not	successful.
31
Running	Jenkins
• Download
• https://jenkins.io/
• Set	environment	variable	(optional)
(default	path:		~/.jenkins)
• Run
32
java -jar jenkins.war [--httpPort=8080]
Starting	and	Accessing	Jenkins
https://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins
JENKINS_HOME=/home/to/jenkins
33
...
Jul 27, 2016 4:59:14 PM jenkins.install.SetupWizard init
INFO:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been
created 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
*************************************************************
*************************************************************
*************************************************************
...
34
35
36
37
Freestyle	Project	Configuration
• Source	Code	Management
• Build	Triggers
• Build	Environment
• Build
• Post-Build	Actions
38
Maven	Project	Configuration
• Source	Code	Management
• Build	Triggers
• Build	Environment
• Build
• Pre	Steps
• Build
• Post	Steps
• Build	Settings
• Post-Build	Actions
39
MultiConfiguration Project	
Configuration
• Source	Code	Management
• Build	Triggers
• Configuration	Matrix
• Build	Environment
• Build
• Post-Build	Actions
40
Work	Behind	Proxy
41
Jenkins	Grid
42
Jenkins	Master/Slave	Mode
• Distribute	the	workload
• Provide	different	environments	needed	for	
builds/tests/deployments
43
Agent	Launch	Methods
• Via	Java	Web	Start
• The	agent	need	not	be	reachable	from	the	master.
• Via	execution	of	command	on	the	master
• Via	SSH	for	agents	on	Unix	machines
• The	slave	needs	to	be	reachable	from	the	master,	and	
you	will	have	to	supply	an	account	that	can	log	in	on	the	
target	machine.
• Control	this	Windows	slave	as	a	Windows	service
• Starts	a	Windows	slave	by	a	remote	management	facility	
built	into	Windows.
44
Labeling	Nodes
• Grouping	nodes	by	
• O.S.:	windows,	linux,	macos…
• Architecture:	x86,	x64…
• Capability:	docker,	jboss-eap…
• What’s	meaningful	to	you
• Restrict	project	run	node	by	Label	Expression
45
postgres && !vm && (linux || freebsd)
Jenkins	Pipeline
46
Pipeline	Script
47
node {
// Mark the code checkout 'stage'....
stage 'Checkout'
// Get some code from a GitHub repository
git 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 build
sh "${mvnHome}/bin/mvn -Dmaven.test.failure.ignore clean package"
step([$class: 'JUnitResultArchiver',
testResults: '**/target/surefire-reports/TEST-*.xml'])
}
48
Must	Have	Plugins
49
testng-plugin(5066)
aws-java-sdk(5138)
embeddable-build-status(5324)
publish-over-ftp(5326)
global-build-stats(5343)
saferestart(5380)
port-allocator(5450)
dynamicparameter(5614)
emailext-template(5631)
text-finder(5684)
scp(5816)
job-dsl(5847)
jackson2-api(5900)
next-build-number(5922)
flexible-publish(5936)
join(6047)
delivery-pipeline-plugin(6067)
xcode-plugin(6075)
extra-columns(6075)
chucknorris(6116)
emma(6143)
configurationslicing(6146)
job-import-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-commons(6850)
ghprb(6914)
nested-view(6977)
powershell(6992)
dry(7094)
m2release(7118)
jquery-ui(7231)
mask-passwords(7276)
performance(7418)
authentication-tokens(7471)
monitoring(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)
simple-theme-plugin(8525)
nodejs(8529)
extended-choice-parameter(8664)
nodelabelparameter(8710)
build-flow-plugin(8791)
scriptler(8800)
jira(9035)
build-monitor-plugin(9296)
analysis-collector(9666)
log-parser(9858)
mercurial(10026)
config-file-provider(10120)
findbugs(10566)
disk-usage(10583)
promoted-builds(10804)
deploy(10885)
groovy(11094)
git-parameter(11173)
warnings(11288)
thinBackup(11411)
jenkins-multijob-plugin(11441)
pmd(11451)
postbuild-task(11594)
build-name-setter(12007)
violations(12025)
ruby-runtime(12054)
multiple-scms(12256)
rebuild(13156)
msbuild(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)
htmlpublisher(21602)
ssh-agent(21616)
github-organization-folder(22666)
github-branch-source(23954)
timestamper(24135)
greenballs(25435)
copyartifact(25447)
build-timeout(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)
workflow-multibranch(28923)
momentjs(29860)
handlebars(29895)
workflow-aggregator(29983)
run-condition(30104)
branch-api(30341)
workflow-cps-global-lib(30519)
analysis-core(31396)
workflow-durable-task-step(31586)
ws-cleanup(31678)
workflow-basic-steps(32051)
workflow-job(32349)
workflow-cps(32438)
ace-editor(32579)
jquery-detached(33204)
workflow-support(33697)
workflow-api(34186)
envinject(34317)
cloudbees-folder(35981)
durable-task(36386)
jquery(38276)
workflow-scm-step(38884)
github(40406)
git-server(40803)
github-api(43238)
structs(43239)
plain-credentials(44323)
parameterized-trigger(46900)
email-ext(50123)
icon-shim(52730)
workflow-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)
matrix-project(125657)
windows-slaves(126388)
antisamy-markup-formatter(126489)
maven-plugin(127956)
subversion(128710)
matrix-auth(129015)
ldap(131841)
ssh-slaves(132146)
pam-auth(132151)
ant(132412)
external-monitor-job(132612)
ssh-credentials(132621)
credentials(132919)
javadoc(133300)
mailer(133547)
s/green/blue/g
• It's	not	for	color	blind	users.
• It's	all	about																(influenced	by															):
• Green	Balls	Plugin
• https://wiki.jenkins-
ci.org/display/JENKINS/Green+Balls
50
青Cyan #00FFFF
“Why	does	Jenkins	have	blue	balls?” on	2012-03-13	by R.	Tyler	Croy
https://jenkins.io/blog/2012/03/13/why-does-jenkins-have-blue-balls/
• Gravatar - Globally	Recognized	Avatar
• Register	your	own	avatar
• at	https://en.gravatar.com/
• Make	it	easier	to	identify	one
51
Static	Code	Analyses
52
• Checkstyle
• DRY
• FindBugs
• PMD
• Compiler	Warnings
• Task	Scanner
• TODO,	FIXME,	XXX...
Plugins	Available
• FindBugs Plugin
• Checkstyle Plugin
• PMD	Plugin
• DRY	Plugin
• JaCoCo Plugin
• Warnings	Plugin
53
Job	Configuration	History
• Record	every	single	change
• Saves	a	copy	of	the	configuration	file	of	a	job	
(config.xml)	for	every	change	made.
54
SCM	Sync	Configuration
• Keep	sync'ed configurations	with	a	SCM	repository.
• Track	changes	(and	author)	made	on	every	file	with	
commit	messages.
55
Configuration	Slicing
56
• Perform	mass	configuration	of	select	project	
properties.
Disk	Usage
• Keep	watching!
57
Future	of	Jenkins
58
59
Project	Blue	Ocean
60
Your	Turn	Now!
61

CI, CD and Jenkins 2