Jenkins: The Definitive Guide
John Ferguson Smart
Copyright 2011 John Ferguson Smart
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (.
Nutshell Handbook, the Nutshell Handbook logo, and the OReilly logo are registered trademarks of OReilly Media, Inc. Jenkins: The Definitive Guide , the image of an ornate chorus frog, and related trade dress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and OReilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps.
Jenkins: The Definitive Guide is available under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
O'Reilly Media
Foreword
Kohsuke Kawaguchi
Creator of the Jenkins project and Architect at CloudBees
Seven years ago, I wrote the first line of code that started this whole project that is now known as Jenkins, and was originally called Hudson. I used to be the guy who broke the build, so I needed a program to catch my mistakes before my colleagues did. It was just a simple tool that did a simple thing. But it rapidly evolved, and now Id like to think that its the most dominant CI server on the market bar none, encompassing a broad plugin ecosystem, commercial distributions, hosted Jenkins-as-a-Service, user groups, meet-ups, trainings, and so on.
As with most of my other projects, this project was open-sourced since its inception. Over its life it critically relied on the help and love of other people, without which the project wouldnt be in the current state. During this time Ive also learned a thing or two about running open source projects. From that experience, I think people often overlook that there are many ways to help an open source project, of which writing code is just one of many. Theres spreading words, helping other users, organizing meet-ups, and yes, theres writing documentation.
In this sense, John is an important part of the Jenkins community, even though he hasnt contributed codeinstead, he makes Jenkins more approachable to new users. For example, he has a popular blog thats followed by many, where he regularly talks about continuous integration practices and other software development topics. He is good at explaining things so that people new to Jenkins can still understand them, which is something often hard for people like me who develop Jenkins day in day out. He is also well-known for his training courses, of which Jenkins is a part. This is another means by which he makes Jenkins accessible for more people. He clearly has a passion for evangelizing new ideas and teaching fellow developers to be more productive.
These days I spend my time at CloudBees where I focus my time on Open Source Jenkins, the CloudBees pro version of Jenkins where we build plugins on top of Jenkins, and taking Jenkins to the private and public cloud with CloudBees DEV@cloud service. In this role I now have more interaction with John than before, and my respect for his passion has only grown.
So I was truly delighted that he took on the daunting task of writing a book about Jenkins. It gives a great overview of the typical main ingredients of continuous integration. And for me personally, I always get asked if theres a book about Jenkins, and I can finally answer this question positively! But more importantly, this book reflects his passion, and his long experience in teaching people how to use Jenkins, in combination with other things. But dont take my words for it. Youll just need to read on to see it for yourself.
Preface
Audience
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 as 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.
Book Layout
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.
Jenkins or Hudson?
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.
Font Conventions
This book follows certain conventions for font usage. Understanding these conventions up-front makes it easier to use this book.
ItalicUsed for filenames, file extensions, URLs, application names, emphasis, and new terms when they are first introduced.
Constant width
Used for Java class names, methods, variables, properties, data types, database elements, and snippets of code that appear in text.
Constant width bold