Jenkins
Jenkins
2012-05-14
Chris Shenton
@shentonfreude
[email protected]
http://koansys.com/tech/jenkins/
We're a small consulting company with Federal, non-profit and startup clients.
We're UNIX guys who do python, pyramid, mongodb, plone, etc.
What’s Continuous
Integration?
Continuous Integration is a software development
practice where members of a team integrate their
work frequently, usually each person integrates at
least daily - leading to multiple integrations per day.
Each integration is verified by an automated build
(including test) to detect integration errors as
quickly as possible. Many teams find that this
approach leads to significantly reduced integration
problems and allows a team to develop cohesive
software more rapidly.
-- Martin Fowler
Nowadays, developers tend to commit code checkins much more frequently, so se can checkout and build many times
throughout the day.
Continuous Integration:
Some Free Systems
• Cruise Control
• BuildBot
• Hudson/Jenkins
Cruise Control and Jenkins are Java, BuildBot is Python: they all can build projects written in any language. I find Jenkins to
be the easiest to setup, and have the most active developer community
Hudson replaced by Jenkins
Dismissed by Forked by
Oracle Community
Written by Kosuke Kawaguchi while at Sun
Since the split in November:
* 4x increase in commits and fixed tickets
* Over 13,000 downloads a week
* 1500 users on mailing list, 4000 followers on twitter
How Developers Code
while ( not done ) {
write some code;
test by poking at it tediously;
fix the bugs you see;
}
deploy;
cross your fingers nobody finds new bugs;
return;
Isn’t There Enough
World Suffering??
How to Improve It?
• What if we could hire a new developer?
• Make them test all day long
• Every time we make a code change
• Track and report progress
• Give metrics, graphs on improvements
• Report failures quickly
That New Guy is Jenkins
• Profit!
For production use, youʼd put this behind Apache or Tomcat or something,
and youʼd want to have access controls on it,
or use Jenkinsʼ built-in user manager
Distributed Builds
Chris Shenton
!health
Jenkins ContinuousIntegration
health of all projects:
pyrajenkins: Health [Build stability: 1 out of the last 5 builds failed.(80%), Cobertura Coverage: 72%
(78/108) Lines(90%), Test Result: 0 tests failing out of a total of 7 tests.(100%): http://localhost:8080/
job/pyrajenkins/6/
webcompare: Health [Build stability: 2 out of the last 5 builds failed.(60%): http://localhost:8080/job/
webcompare/17/
Jenkins ContinuousIntegration
Project pyrajenkins build #7: FAILURE in 24 sec: http://localhost:8080/job/pyrajenkins/7/
Chris Shenton: Add support for pylint so Jenkins can yell at me
Jenkins ContinuousIntegration
Yippie, build fixed!
Project pyrajenkins build #9: FIXED in 5.5 sec: http://localhost:8080/job/pyrajenkins/9/
I find the IM integration to be flakey sometimes, the first command works, subsequent ones get no response; might be
a bug (see the tracker), might be network/firewall, or could be me.
Helpful Plugins
• Subversion: code repo checkout
• Git: code repo checkout, build all branches
• Cobertura: test coverage reporter
• Maven: many plugins available
• Various style violations checkers
• Continuous Integration Game: high scores
• Chuck Norris: motivational help :-)
Over 300 Plugins
• Authentication: LDAP, AD, OpenID, SQL, ...
• Trac, GitHub, Jira, Redmine: trackers
• Selenium, Sauce, Windmill: functional,
click testing
• Ambient Orbs
• Lava Lamps
• Code Smells
At a recent sprint, we had a bunch of coders all working on one project. If any of them committed code that broke the
build, Jenkins alerted us immediately, the responsible developer was notified, and they could fix the problem before
other developers were affected. This was a big help, and avoided a lot of frustration.
Critical Prerequisites:
Automated Build
def test_normalize_url(self):
self.assertEquals(w._normalize_url("http://example.com/something"),
"http://example.com/something")
self.assertEquals(w._normalize_url("http://example.com/something/RSS"),
"http://example.com/something")
self.assertEquals(w._normalize_url("http://example.com?querystring"),
"http://example.com")
self.assertEquals(w._normalize_url("http://example.com#fragment"),
"http://example.com")
Recap
• Jenkins watches the code repo for commits
• Checks out code
• Builds it with your build ‘scripts’
• Runs your tests: unit, performance, UI, ...
• Reports problems by email, IM, etc
• Tracks and graphs metrics and trends
• Can build artifacts, deploy, etc
Take Away
Poll SCM
Schedule
Build after other projects are built */10 * * * *
Subversion Recordoffingerprints
Record fingerprints files to trackofusage
files to track usage
Subversion
BuildBuild
afterafter
otherother projects
projects are built
are built Publish
Publish Cobertura Cobertura
Coverage Coverage Report
Report
1. Give it a name, a code repo to watch; for Git it can build all branches that change.
2. Poll every 10 minutes, then 3 text boxes with (here) Unix commands to run the build and tests.
It can be tricky to get the tests to run where you want them, and output where Jenkins expects it.
You likely will want to turn these commands into scripts once you get them debugged through the web.
Report
Demo: Create Project (2)
Publish Cobertura Coverage Report
Back to Dashboard
Project pyrajenkins
Status
Demonstration pyramid app for Jenkins talk
edit description
Changes
Disable Project
Workspace Test Result Trend
Build Now
Delete Project
Configure
Coverage Report
Violations
pylint 40
Demo: Status: Failed Test search
Jenkins » pyrajenkins » #5 » Test Results » pyracms.tests » PageEditTests » test_save_url ENABLE AUTO REFRESH
Back to Project
Regression
Status
pyracms.tests.PageEditTests.test_save_url (from nosetests)
Changes Failing for the past 1 build (Since #5 )
Took 0 ms.
Console Output add description
Coberturaʼs designed for Java, so only the Lines applies to my Python code.
The dip at checkin #4 was due to added code without corresponding tests;
I then wrote a test committed in #6 to bring it back up.
Note the Red bars indicating missing coverage.
Demo: Status: Coverage (2)
pylint 49 (+9)
fin
Questions?
http://www.flickr.com/photos/drewdlecam/3501280430/in/photostream/