This book is aimed at relatively technical readers, though no prior experience with Continuous Integration is assumed. You may be new to Continuous Integration, and would like to learn about the benefits it can bring to your development team. Or, you might be using Jenkins or Hudson already, and want to discover how you can take your Continuous Integration infrastructure further.
Much of this book discusses Jenkins in the context of Java or JVM-related projects. Nevertheless, even if you are using another technology stack, this book should give you a good grounding in Continuous Integration with Jenkins. We discuss how to build projects using several non-Java technologies, including Grails, Ruby on Rails and .NET. In addition, many topics, such as general configuration, notification, distributed builds and security are applicable no matter what language you are using.
Continuous Integration is like a lot of things: the more you put in, the more value you will get out. While even a basic Continuous Integration setup will produce positive improvements in your team process, there are significant advantages to gradually assimilating and implementing some of the more advanced techniques as well. To this end, this book is organized as a progressive trek into the world of Continuous Integration with Jenkins, going from simple to more advanced. In the first chapter, we start off with a sweeping overview of what Jenkins is all about, in the form of a high-level guided tour. From there, we progress into how to install and configure your Jenkins server and how to set up basic build jobs. Once we have mastered the basics, we will delve into more advanced topics, including automated testing practices, security, more advanced notification techniques, and measuring and reporting on code quality metrics. Next, we move on to more advanced build techniques such as matrix builds, distributed builds and cloud-based CI, before discussing how to implement Continuous Deployment with Jenkins. Finally, we cover some tips on maintaining your Jenkins server.
As we discuss in the introduction, Jenkins was originally, and up until recently, known as Hudson. In 2009, Oracle purchased Sun and inherited the code base of Hudson. In early 2011, tensions between Oracle and the open source community reached rupture point and the project forked into two separate entities: Jenkins, run by most of the original Hudson developers, and Hudson, which remained under the control of Oracle.
As the title suggests, this book is primarily focused on Jenkins. However, much of the book was initially written before the fork, and the products remain very similar. So, although the examples and illustrations do usually refer to Jenkins, almost all of what is discussed will also apply to Hudson.
Used for filenames, file extensions, URLs, application names, emphasis, and new terms when they are first introduced.
Used for Java class names, methods, variables, properties, data types, database elements, and snippets of code that appear in text.
Constant width bold
Used for commands you enter at the command line and to highlight new code inserted in a running example.
Constant width italic
Used to annotate output.
From time to time, this book discusses command-line instructions.
When we do, output produced by the console (e.g., command prompts or
screen output) is displayed in normal characters, and commands (what you
type) are written in
ls -altotal 168 drwxr-xr-x 16 johnsmart staff 544 21 Jan 07:20 . drwxr-xr-x+ 85 johnsmart staff 2890 21 Jan 07:10 .. -rw-r--r-- 1 johnsmart staff 30 26 May 2009 .owner -rw-r--r--@ 1 johnsmart staff 1813 16 Apr 2009 config.xml drwxr-xr-x 181 johnsmart staff 6154 26 May 2009 fingerprints drwxr-xr-x 17 johnsmart staff 578 16 Apr 2009 jobs drwxr-xr-x 3 johnsmart staff 102 15 Apr 2009 log drwxr-xr-x 63 johnsmart staff 2142 26 May 2009 plugins -rw-r--r-- 1 johnsmart staff 46 26 May 2009 queue.xml -rw-r--r--@ 1 johnsmart staff 64 13 Nov 2008 secret.key -rw-r--r-- 1 johnsmart staff 51568 26 May 2009 update-center.json drwxr-xr-x 3 johnsmart staff 102 26 May 2009 updates drwxr-xr-x 3 johnsmart staff 102 15 Apr 2009 userContent drwxr-xr-x 12 johnsmart staff 408 17 Feb 2009 users drwxr-xr-x 28 johnsmart staff 952 26 May 2009 war
Where necessary, the backslash character at the end of the line is used to indicate a line break: you can type this all on one line (without the backslash) if you prefer. Don’t forget to ignore the “>” character at the start of the subsequent lines—it’s a Unix prompt character:
$ wget -O - http://jenkins-ci.org/debian/jenkins-ci.org.key \ > | sudo apt-key add -
For consistency, unless we are discussing a Windows-specific issue, we will use Unix-style command prompts (the dollar sign, “$”), as shown here:
$ java -jar jenkins.war
$ svn list svn://localhost
However, unless we say otherwise, Windows users can safely use these commands from the Windows command console:
C:\Documents and Settings\Owner> java -jar jenkins.war
C:\Documents and Settings\Owner> svn list svn://localhost
This book was not written alone. Rather, it has been a collaborative effort involving many people playing different roles. In particular, the following people generously contributed their time, knowledge and writing skill to make this a better book:
Evgeny contributed a section on generating your Maven build jobs automatically in Chapter 10.
Matthew McCullough is an energetic 15 year veteran of enterprise software development, open source education, and co-founder of Ambient Ideas, LLC, a Denver consultancy. Matthew currently is a trainer for GitHub.com, author of the Git Master Class series for O’Reilly, speaker at over 30 national and international conferences, author of 3 of the top 10 DZone RefCards, and President of the Denver Open Source Users Group. His current topics of research center around project automation: build tools (Maven, Leiningen, Gradle), distributed version control (Git), Continuous Integration (Jenkins) and Quality Metrics (Sonar). Matthew resides in Denver, Colorado with his beautiful wife and two young daughters, who are active in nearly every outdoor activity Colorado has to offer.
Matthew wrote the section on integrating Git with Jenkins in Chapter 5.
Juven Xu is a software engineer from China who works for Sonatype. An active member of the open source community and recognized Maven expert, Juven was responsible for the Chinese translation of Maven: The Definitive Guide as well as an original Chinese reference book on Maven. He is also currently working on the Chinese translation of the present book.
Juven wrote the section on IRC notifications in Chapter 8.
Rene Groeschke is a software engineer at Cassidian Systems, formerly known as EADS Deutschland GmbH, as well as an open source enthusiast. A certified ScrumMaster with about 7 years experience as a programmer in several enterprise Java projects, he is especially focused on Agile methodologies like Continuous Integration and Test-Driven Development. Besides his daily business, the University of Corporate Education in Friedrichshafen allows him to spread the word about scrum and scrum related topics by giving lectures for the bachelor students of information technology.
Rene contributed the section on building projects with Gradle in Chapter 5.
The technical review process for this book was a little different to the approach taken for most books. Rather than having one or two technical reviewers read the entire book near the end of the book writing process, a team of volunteers from the Jenkins community, including many key Jenkins developers, were able to read chapters as they were written. This review team was made up of the following people: Alan Harder, Andrew Bayer, Carlo Bonamico, Chris Graham, Eric Smalling, Gregory Boissinot, Harald Soevik, Julien Simpson, Juven Xu, Kohsuke Kawaguchi, Martijn Verberg, Ross Rowe, and Tyler Ballance.
Wakaleo Consulting is a consulting company that helps organizations optimize their software development process. Lead by John Ferguson Smart, author of this book and Java Power Tools, Wakaleo Consulting provides consulting, training and mentoring services in Agile Java Development and Testing Practices, Software Development Life Cycle optimization, and Agile Methodologies.
Wakaleo helps companies with training and assistance in areas such as Continuous Integration, Build Automation, Test-Driven Development, Automated Web Testing and Clean Code, using open source tools such as Maven, Jenkins, Selenium 2, and Nexus. Wakaleo Consulting also runs public and on-site training around Continuous Integration and Continuous Deployment, Build Automation, Clean Code practices, Test-Driven Development and Behavior-Driven Development, including Certified Scrum Developer (CSD) courses.
CloudBees is the only cloud company focused on servicing the complete develop-to-deploy life cycle of Java web applications in the cloud. The company is also the world’s premier expert on the Jenkins/Hudson continuous integration tool.
Jenkins/Hudson creator Kohsuke Kawaguchi leads a CloudBees team of experts from around the world. They’ve created Nectar, a supported and enhanced version of Jenkins that is available on-premise by subscription. If you depend on Jenkins for mission-critical software processes, Nectar provides a highly-tested, stable, and fully-supported version of Jenkins. It also includes Nectar-only functionality such as automatic scaling to VMware virtual machines.
If you’re ready to explore the power of continuous integration in the cloud, CloudBees makes Jenkins/Hudson available as part of its DEV@cloud build platform. You can get started with Jenkins instantly and can scale as needed—no big up-front investment in build servers, no more limited capacity for builds, and no maintenance hassles. Once an application is ready to go live, you can deploy on CloudBees’s RUN@cloud Platform as a Service in just a few clicks.
With CloudBees’s DEV@cloud and RUN@cloud services, you don’t have to worry about servers, virtual machines or IT staff. And with Nectar, you enjoy the most powerful, stable, supported Jenkins available.
Odd-e is an Asian-based company that builds products in innovative ways and helps others achieve the same. The team consists of experienced coaches and product developers who work according to the values of scrum, agile, lean, and craftsmanship, and the company is structured the same way. For example, Odd-e doesn’t have an organizational hierarchy or managers making decisions for others. Instead, individuals self-organize and use all their skills to continuously improve their competence. The company provides training and follow-up coaching to help others collaboratively seek and develop a better way of working.
It is not the job but the values that binds Odd-e together. Its members love building software, value learning and contribution over maximizing profit, and are committed to supporting open source development in Asia.
This book is an open source book, published under the Creative Commons License. The book was written in DocBook, using XmlMind. The book’s source code can be found on GitHub at http://www.github.org/wakaleo/jenkins-the-definitive-guide.
The sample Jenkins projects used in this book are open source and freely available online—see the book’s web page at http://www.wakaleo.com/books/jenkins-the-definitive-guide for more details.
This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Jenkins: The Definitive Guide by John Ferguson Smart (O’Reilly). Copyright 2011 John Ferguson Smart, 978-1-449-30535-2.”
If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at email@example.com.
Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://safaribooksonline.com.
|O’Reilly Media, Inc.|
|1005 Gravenstein Highway North|
|Sebastopol, CA 95472|
|800-998-9938 (in the United States or Canada)|
|707-829-0515 (international or local)|
We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:
To comment or ask technical questions about this book, send email to:
For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com.
Find us on Facebook: http://facebook.com/oreilly
Follow us on Twitter: http://twitter.com/oreillymedia
Watch us on YouTube: http://www.youtube.com/oreillymedia
First and foremost, my wonderful wife, Chantal, and boys, James and William, without whose love, support, and tolerance this book would not have been possible.
I would like to thank Mike Loukides for working with me once again on this book project, and the whole O’Reilly team for their high standards of work.
Thank you to Kohsuke Kawaguchi for having created Jenkins, and for still being the driving force behind this brilliant product. Thanks also to Francois Dechery, Sacha Labourey, Harpreet Singh, and the rest of the CloudBees team for their help and support.
I am also very grateful to those who took the time and energy to contribute work to the book: Evgeny Goldin, Matthew McCullough, Juven Xu, and Rene Groeschke.
A great thanks goes out to the following reviewers, who provided valuable feedback throughout the whole writing process: Alan Harder, Andrew Bayer, Carlo Bonamico, Chris Graham, Eric Smalling, Gregory Boissinot, Harald Soevik, Julien Simpson, Juven Xu, Kohsuke Kawaguchi, Martijn Verberg, Ross Rowe, and Tyler Ballance.
Thank you to Andrew Bayer, Martijn Verburg, Matthew McCullough, Rob Purcell, Ray King, Andrew Walker, and many others, whose discussions and feedback provided me with inspiration and the ideas that made this book what it is.
And many other people have helped in various ways to make this book much richer and more complete than it would have been otherwise: Geoff and Alex Bullen, Pete Thomas, Gordon Weir, Jay Zimmerman, Tim O’Brien, Russ Miles, Richard Paul, Julien Simpson, John Stevenson, Michael Neale, Arnaud Héritier, and Manfred Moser.
And finally a great thank you to the Hudson/Jenkins developer and user community for the ongoing encouragement and support.