jenkins at your continuous service
TRANSCRIPT
01
About meBio: Developer, coach, speaker, author
Company: Aestas/IT (http://aestasit.com)
Email: [email protected]
Linkedin: http://www.linkedin.com/in/andreyadamovich
Lanyrd: http://lanyrd.com/profile/andreyadamovich
GitHub: https://github.com/aadamovich
SO: http://stackoverflow.com/users/162792/andreyadamovich
Twitter: @codingandrey, @aestasit
••••••••
02
Let's start!03
Who is mr. Jenkins?
04
A bit of history: HudsonWork started in the summer of 2004 at Sun by Kohsuke Kawaguchi.
First release: February 2005.
In May, 2008, Hudson won the Duke's Choice Award in the Developer
Solutions category.
In 2010, Sun is acquired by Oracle... discussions, negotiations.
Kohsuke Kawaguchi leaves Oracle.
•••
••
05
A bit of history: JenkinsIn 2010, majority of Hudson's community votes for forking and name
changing.
Initial release of Jenkins: 2nd of February, 2011.
Oracle still supports and develops Hudson.
Around 20102011, CloudBees is created and declared Jenkins as its
backbone product.
•
•••
06
Current stateLatest version: 1.651 (LTS: 1.642.2 ).
jenkinsci organization on Github has 600+ members
... and over 1400 Git repositories.
1100+ plugins available.
Uncountable number of installations and users.
Jenkins 2.0, most likely, is coming this year.
••••••
07
Vibrant and lively
08
Jenkins is useful for...Building (compiling, assembling, linking, etc.)...
...and Reporting the build status.
Testing and, more importantly, Reporting the test results.
Releasing, Deploying, Provisioning...
...or simply Executing any of your automation tasks.
So...
Jenkins is an ultimate control panel for your software delivery!
•••••••
09
Tools using/integrating with JenkinsFabric8 http://fabric8.io/
MaestroDev http://maestrodev.wix.com/maestrodev
IBM BlueMix https://hub.jazz.net/
XebiaLabs https://xebialabs.com/
••••
10
Starting Jenkinsjava ‐jar jenkins.war01.
11
Starting Jenkins: Debianwget ‐q ‐O ‐ \
https://jenkins‐ci.org/debian/jenkins‐ci.org.key | \
sudo apt‐key add ‐
sudo sh ‐c 'echo deb \
http://pkg.jenkins‐ci.org/debian binary/ \
\> /etc/apt/sources.list.d/jenkins.list'
sudo apt‐get update
sudo apt‐get install jenkins
01.
02.
03.
04.
05.
06.
07.
08.
12
Starting Jenkins: RedHatsudo wget ‐O /etc/yum.repos.d/jenkins.repo \
http://pkg.jenkins‐ci.org/redhat‐stable/jenkins.repo
sudo rpm ‐‐import \
https://jenkins‐ci.org/redhat/jenkins‐ci.org.key
sudo yum install jenkins
01.
02.
03.
04.
05.
13
Good start,but...
14
What's thefirst thing you
do...15
in Jenkinsafter
installation?16
Remove TheBlue Balls!17
Green balls
18
Green balls
19
But ifseriously...20
Jenkins has lots of plugins
21
Jenkinsneeds to bemaintained!22
Maintaining your installationDevelopers need more tools to build their software.
Developers need more plugins to better integrate build tools and
increase visibility.
Developers need faster feedback from their builds.
It's not enough to just start the WAR file!
••
••
23
Installing Jenkins: better wayFor more reliable setup, it's better to use provisioning tools to describe
your requirements:
Puppet
Chef
Ansible
your favorite provisioning tool here
••••
24
Installing Jenkins: Puppethttps://forge.puppetlabs.com/rtyler/jenkins
class { 'jenkins':
executors => 4,
}
jenkins::plugin { 'git':
version => '1.1.11',
}
01.
02.
03.
04.
05.
06.
25
Installing Jenkins: Puppethttps://forge.puppetlabs.com/rtyler/jenkins
jenkins::job { 'test‐build‐job':
enabled => 0,
config =>
template("${templates}/test‐build‐job.xml.erb"),
}
01.
02.
03.
04.
05.
26
Installing Jenkins: Ansiblehttps://github.com/geerlingguy/ansiblerolejenkins
‐ hosts: ci‐server
vars:
jenkins_plugins:
‐ git
‐ ssh
roles:
‐ geerlingguy.jenkins
01.
02.
03.
04.
05.
06.
07.
27
Installing Jenkins: Chefhttps://github.com/chefcookbooks/jenkins
include_recipe 'jenkins::master'
jenkins_plugin 'greenballs' do
version '1.3'
end
jenkins_user 'grumpy' do
action :delete
end
01.
02.
03.
04.
05.
06.
07.
28
Installing Jenkins: Dockerdocker run ‐p 8080:8080 ‐p 50000:50000 \
‐‐name myjenkins \
‐‐env JAVA_OPTS=... \
‐v /var/lib/jenkins:/var/jenkins_home \
jenkins
01.
02.
03.
04.
05.
29
Installing Jenkins: DockerfileFROM jenkins
COPY plugins.txt /usr/share/jenkins/ref/
COPY custom.groovy \
/usr/share/jenkins/ref/init.groovy.d/custom.groovy
RUN /usr/local/bin/plugins.sh \
/usr/share/jenkins/ref/plugins.txt
01.
02.
03.
04.
05.
06.
30
ConfiguringJenkins
31
JobConfigHistoryhttps://wiki.jenkinsci.org/display/JENKINS/JobConfigHistory+Plugin
32
Jenkins asCode
33
Job DSLhttps://jenkinsci.github.io/jobdslplugin/
job(jobName) {
scm {
git("git://github.com/${project}.git", branchName)
}
steps {
maven("test ‐Dproject.name=${project}/${branchName}")
}
}
01.
02.
03.
04.
05.
06.
07.
08. 34
Gradle Jenkins pluginhttps://github.com/ghale/gradlejenkinsplugin
Allows defining jobs and views with the help of Job DSL inside Gradle
build.
Gives common tasks to create, update, delete jobs and views on
Jenkins server(s).
••
•
35
Gradle Jenkins pluginapply plugin: 'com.terrafolio.jenkins'
jenkins {
servers {
testing {
url 'http://jenkins.somewhere.com:8080'
}
}
...
01.
02.
03.
04.
05.
06.
07.
08.
36
Gradle Jenkins plugin: definition ...
jobs {
test {
server servers.testing
definition {
name "Build ${project.name}"
xml file('config.xml')
}
}}}
01.
02.
03.
04.
05.
06.
07.
08.
09. 37
Gradle Jenkins plugin: templatestemplates {
build_template {
dsl {
triggers { scm '*/5 * * * *' }
steps { gradle 'clean build' }
publishers {
archiveJunit 'build/test‐results/*.xml'
archiveArtifacts 'build/libs/*.jar'
}}}}
01.
02.
03.
04.
05.
06.
07.
08.
09. 38
Gradle Jenkins plugin: mixingjobs {
for (i in 1..3) {
"build${i}" {
dsl {
using 'build_template'
customWorkspace "/workspaces/build${i}"
scm {
git("[email protected]/build_repo_${i}")
}
}}}}
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.39
Gradle Jenkins plugin: viewsview {
name "Even jobs"
jobs {
name "Build Job 2"
}
columns {
name()
buildButton()
}}
01.
02.
03.
04.
05.
06.
07.
08.
09. 40
Gradle Jenkins plugin: tasksupdateJenkinsItems
deleteJenkinsItems
dumpJenkinsItems
dumpRemoteJenkinsItems
retireJenkinsItems
validateJenkinsItems
••••••
41
Constructingpipelines
42
Build Flowhttps://wiki.jenkinsci.org/display/JENKINS/Build+Flow+Plugin
43
Build Flow: simplebuild("job2A")
build("job2B")
build("job2C")
01.
02.
03.
44
Build Flow: guardguard {
build( "this_job_may_fail" )
} rescue {
build( "cleanup" )
}
01.
02.
03.
04.
05.
45
Build Flow: retryretry (3) {
build( "this_job_may_fail" )
}
01.
02.
03.
46
Build Flow: parallelparallel (
// job 1, 2 and 3 will
// be scheduled in parallel.
{ build("job1") },
{ build("job2") },
{ build("job3") }
)
// job4 will be triggered after jobs 1, 2, 3 complete
build("job4")
01.
02.
03.
04.
05.
06.
07.
08.
09. 47
Build Flow: parallelparallel (
{
build("job1A")
build("job1B")
},
{
build("job2A")
build("job2B")
}
)
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.48
Build Pipelinehttps://wiki.jenkinsci.org/display/JENKINS/Build+Pipeline+Plugin
49
Reporting50
Timestamperhttps://wiki.jenkinsci.org/display/JENKINS/Timestamper
21:51:15 Started by user anonymous
21:51:15 Building on master
21:51:17 Finished: SUCCESS
01.
02.
03.
51
ANSI Colorhttps://wiki.jenkinsci.org/display/JENKINS/AnsiColor+Plugin
52
TAP53
Test Anything ProtocolTAP, the Test Anything Protocol, is a simple textbased interface
between testing modules in a test harness. TAP started life as part of
the test harness for Perl but now has implementations in C, C++,
Python, PHP, Perl, Java, JavaScript, and others.
54
TAP format: simple1..2
ok 1 ‐ Yahoo!
not ok 2 ‐ org.tap4j.Error...
01.
02.
03.
55
TAP format: nested1..2
ok 1 ‐ First test
1..2
ok 1 ‐ This is a subtest
ok 2 ‐ So is this
1..2
ok 1 ‐ This is a subtest
ok 2 ‐ So is this
ok 2 ‐ 2nd test
01.
02.
03.
04.
05.
06.
07.
08.
09. 56
TAP for Jenkinshttps://wiki.jenkinsci.org/display/JENKINS/TAP+Plugin
57
TAP for Jenkins
58
Jenkins TVhttps://wiki.jenkinsci.org/display/JENKINS/Build+Monitor+Plugin
59
Jenkins TV
60
Custom warningshttps://wiki.jenkinsci.org/display/JENKINS/Warnings+Plugin
61
Custom warningsSupport for javac (ant, maven, command line),
Eclipse Java Compiler, JavaDoc Compiler,
Hudson/Jenkins HPI, MSBuild, GCC, GNU Linker,
SUN Studio C++, Gnat (Ada), Erlang,
PCLint compiler warnings (configuration of PcLint),
Eclipse Buckminster, Oracle Invalids, Doxygen,
Robocopy, Perforce, Cobol, PHP, Flex, YUI Compressor,
puppetlint, FxCop, C++ lint, CSSLint, JCReport,
and many more...
••••••••• 62
Custom warnings
63
Build labels
64
Groovy Postbuild pluginhttps://wiki.jenkinsci.org/display/JENKINS/Groovy+Postbuild+Plugin
65
Groovy Postbuild plugin
66
Groovy Postbuild pluginif(manager.
logContains(".*uses or overrides a deprecated API.*")) {
manager.
addWarningBadge("Thou shalt not use deprecated methods.")
manager.
createSummary("warning.gif").
appendText("<h1>You have been warned!</h1>",
false, false, false, "red")
manager.buildUnstable()
}
01.
02.
03.
04.
05.
06.
07.
08.
09.
10.67
Groovy Postbuild plugin
68
Groovy Postbuild pluginif("true".equals(
manager.build.buildVariables.get("storeToDB"))) {
manager.addBadge("db_in.gif", "Stored to DB")
}
01.
02.
03.
04.
69
Groovy Postbuild plugin
70
Groovy Postbuild pluginif(manager.build.result.
isBetterOrEqualTo(
hudson.model.Result.UNSTABLE)) {
manager.
addShortText(
"v${manager.build.buildVariables.get('version')}"
)
}
01.
02.
03.
04.
05.
06.
07.
08.
71
Groovy Postbuild plugin
72
Groovy Postbuild plugindef matcher = manager.getLogMatcher(".*Total time: (.*)\$")
if(matcher?.matches()) {
manager.
addShortText(
matcher.group(1),
"grey", "white", "0px", "white"
)
}
01.
02.
03.
04.
05.
06.
07.
08.
73
Groovy Postbuild plugin
74
Groovy Postbuild plugin: iconsmanager.addBadge("star‐gold.gif", "icon from Jenkins")
manager.addBadge("yellow.gif",
"icon from groovy‐postbuild plugin")
manager.addBadge("/images/16x16/yellow.gif",
"icon from Jenkins")
manager.addBadge("/plugin/greenballs/16x16/green.gif",
"icon from greenballs plugin")
01.
02.
03.
04.
05.
06.
07.
75
ChatOps76
ChatOpsHipchat
Slack
Skype
Jabber/XMPP
etc.
•••••
77
ChatOps: Slack
78
ScalingJenkins
79
Single server
80
Master/Slave
81
Labelling
82
Slaves vs.Executors
83
Why scale?84
Feedback loop
85
Reason 186
Monolithicbuild
87
Monolithic buildTimeconsuming
Resourceconsuming
Frustrationaccumulating
•••
88
Before youcan scale...89
SPLIT!!!90
Reason 291
Too manythings tobuild
92
Too many things to buildToo many components
Too many branches
Too many unit/integration tests
Too many validation rules
••••
93
Reason 394
Too manythings to test
95
Too many test variationsDifferent operating systems
Different target platforms
Different markets
Different customers
••••
96
Reason 497
Lack ofresources
98
Reason 599
Lack of time!100
Solutions?101
Add morehardware!
102
or...103
Go to theCloud!
104
Cloud slaves
105
Slave/Executor scaling
106
Jenkins EC2 pluginAllow Jenkins to start slaves on EC2 or Ubuntu Enterprise Cloud
(Eucalyptus) on demand, and kill them as they get unused. With this
plugin, if Jenkins notices that your build cluster is overloaded, it'll start
instances using the EC2 API and automatically connect them as
Jenkins slaves.
“107
Configure access/secret key
108
Configure key pair
109
Configure security group
110
Select machine imageAmazon base images
AWS market place
Create your own
•••
111
Configure EC2 plugin
112
Configure EC2 plugin
113
Configure EC2 plugin
114
Conclusion115
Recommendations
116
Recommendations: job structureDo not make your build to depend on too many plugins.
Do not implement too many build steps inside a job.
There should be a possiblity to execute full build job from a command
line at any machine.
Jenkins is just an executor engine!
And a report collector!
•••
••
117
Recommendations: configurationUse provisioning tools to control complex Jenkins installations...
... and to scale them quicker.
(Optionally) use containers to isolate build tools from each other.
(Optionally) use containers to run acceptance/functional tests of your
applications.
Use Job DSL to define job templates!
••••
•
118
Recommendations: securityEnable HTTPS.
Enable Jenkins security.
Configure LDAP with users and groups.
•••
119
Recommendations: multimasterRunning all your projects in the same Jenkins farm is not always a
good idea.
If your operations are profiecient in supporting single Jenkins
installation, they will be able to setup more.
Indepedent projects should leave in isolation.
•
•
•
120
That's it!121
Jenkins 2.0Pipeline as code aka Jenkinsfile
Improved UX e.g. recommended plugins
Improved UI: job creation, view creation etc.
Improved website: better documentation, plugin index etc.
Totally backwards compatible!
•••••
122
Now, that's itfor sure!
123
Thank you!124