Table Of ContentPraise for Jenkins 2: Up and Running
“This is now both my new go-to book for reference as well as the one I recommend to
those new to Jenkins. It’s quite a feat to write a book that can serve both audiences and
Brent has pulled it off in spades.”
Chaim “Tinjaw” Krause
“Brent Laster does a fantastic job at distilling the power of Jenkins down to its essential
components while still providing the comprehensive guide to getting the most out of
Jenkins 2. Valuable examples of the pipeline as code provide building blocks for
implementing continuous delivery. This belongs in the toolbox of new and experienced
Jenkins users alike.”
Brian Dawson, DevOps Evangelist, CloudBees
Jenkins 2: Up and Running
Evolve Your Deployment Pipeline for Next-Generation Automation
Brent Laster
Jenkins 2: Up and Running
by Brent Laster
Copyright © 2018 Brent Laster. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA
95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://oreilly.com/safari). For more
information, contact our corporate/institutional sales department: 800-998-9938 or
corporate@oreilly.com.
Acquisitions Editor: Brian Foster
Development Editor: Angela Rufino
Production Editor: Justin Billing
Copyeditors: Dwight Ramsey and Rachel Head
Proofreader: Jasmine Kwityn
Indexer: Judith McConville
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Rebecca Demarest
May 2018: First Edition
Revision History for the First Edition
2018-05-02: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491979594 for release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. Jenkins 2: Up and
Running, the cover image, and related trade dress are trademarks of O’Reilly Media,
Inc.
While the publisher and the author have used good faith efforts to ensure that the
information and instructions contained in this work are accurate, the publisher and the
author disclaim all responsibility for errors or omissions, including without limitation
responsibility for damages resulting from the use of or reliance on this work. Use of
the information and instructions contained in this work is at your own risk. If any code
samples or other technology this work contains or describes is subject to open source
licenses or the intellectual property rights of others, it is your responsibility to ensure
that your use thereof complies with such licenses and/or rights.
978-1-491-97959-4
[LSI]
To my best friend and wife, Anne-Marie,
who brings beauty and happiness to each day.
And to my sons Walker, Chase, and Tanner,
who have taught me more than I could ever teach them.
Foreword
The software development industry is going through a slow but real transformation.
Software is increasingly a part of everything, and we, the software developers, are
trying to cope with this exploding demand through more automation. I’d imagine you
are reading this book because you are a part of that transformation.
To serve you better in this transformation, Jenkins is itself going through a major
transformation of its own as well — from the world of “classic” Jenkins, where you
configure Jenkins through a series of jobs from server-rendered GUI, to the world of
“modern” Jenkins, where you configure Jenkins through Jenkinsfiles in Git
repositories and look at results through a pleasant single-page application.
As we develop the modern Jenkins in the community and roll out these new features, I
keep running into this challenge. Most users are simply unaware of this transformation
that’s going on in Jenkins. People keep using Jenkins like they have been doing for
years!
And to be fair, it made complete sense. On the one hand is people’s inertia and this
massive body of information and knowledge accumulated in Google, Stack Overflow,
our mailing lists, issue trackers, and so on that tells people how to effectively use
Jenkins the “classic” way. On the other hand, we have the community that is, generally
speaking, too busy building the “modern” Jenkins; and collectively not enough effort
has been spent on telling people how to effectively use Jenkins the modern way.
So I was very happy to hear about this book, which really takes this challenge head on.
In this book, Brent steps back and forgets everything we’ve known about Jenkins from
the past decade. Then he goes on to reconstruct how Jenkins should be used today.
Unlike Google, Stack Overflow, and so on, where knowledge is captured piecemeal,
this book gives you a systematic path to explore the whole landscape, which makes it
really valuable.
It’s an ideal book for those who are new to CI/CD, as well as those who have been
using Jenkins for many years. This book will help you discover and rediscover
Jenkins.
Kohsuke Kawaguchi
Creator of Jenkins
CTO, CloudBees, Inc.
February 2018
Preface
How to Use This Book
This book is big — bigger than I ever thought it would be. I’ve worried about this at
some level, but decided that there were two ways to go when writing it: I could either
limit the content to only what was needed to do a basic tutorial, or I could spend some
time explaining concepts, creating code examples, and diving into what terminology,
functions, and programming with pipelines-as-code really mean. If you’ve scanned the
book, you can probably figure out that I opted to do the latter.
My reasoning for that was due to my experiences over many years of training people
on using Jenkins. In a short class or workshop, we could only cover a small number of
topics. And people were always hungry for more — more detail and more examples
that they could apply. At the end of conference presentations, I would invariably get
lines of people asking for more information sources, examples, and where to find info
about such and such. Oftentimes, it would come down to “Google this” or “See this
question on Stack Overflow.” Nothing wrong with that, but also not the most
convenient approach.
This book is intended to help you find answers on how to use this powerful
technology. Granted, it’s more mechanics than DevOps, but chances are if you are
reading this, you already have some grasp of continuous integration (CI), continuous
deployment (CD), DevOps, and Jenkins, and are looking for how to make the most out
of the new Jenkins features.
So here are a few guidelines (feel free to use them or ignore them as fits your
situation):
Don’t try to read the entire book through — unless you need to get a lot of sleep.
Scan the sections listed in the Table of Contents. A chapter’s title only hints at its
full contents. Also, don’t forget about consulting the index to find topics you
might be interested in.
If you want to understand the basic ideas and get going quickly, read the first two
chapters and then start playing with some basic pipelines. As you run into
questions or problems, consult the appropriate chapters in the book for the
particular areas.
If you already know the basics of Jenkins and want to convert to pipelines-as-
code, take a look at Chapter 10 to get some ideas on conversions and then consult
other chapters as needed.
If you’re looking to create a larger pipeline, take a look at the chapter on
conversions and the various chapters on integration with the OS and other
technologies (Chapters 10–14). And don’t forget about security — there’s a
chapter on that, too (Chapter 5).
If you’re looking to automate Jenkins, take a look at Chapter 15.
If you run into problems, each chapter contains some details that may help. Look
at the notes, warnings, and sidebars for information on unusual situations or
functionality that may trip you up (or provide an advantage you hadn’t thought
about). There’s also a chapter on more general troubleshooting at the end of the
book.
I freely acknowledge the problem with any technical book these days: that the
technology is rapidly evolving. Over the course of writing the chapters for the book,
I’ve gone back and tried to keep up with the latest changes and innovations and revised
as appropriate. It is my firm belief that the material in the book will provide you with a
good foundation and reference for working with Jenkins 2. But, of course, you should
always consult the latest community documentation for updates and new innovations.
Finally, a request — even if you don’t need to read most of the book, if you find the
parts you read useful, please take a moment and post a review. The main way people
find out about useful books is by word of mouth and online reviews. Your review can
have a tremendous impact.
Thank you, and I hope to see you in a future training or conference!
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program
elements such as variable or function names, databases, data types, environment
variables, statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
<Constant width in angle brackets>
Shows text that should be replaced with user-supplied values or by values
determined by context.
TIP
This element signifies a tip or suggestion.
NOTE
This element signifies a general note.
WARNING
This element indicates a warning or caution.
Using Code Examples
Supplemental material (code examples, exercises, etc.) is available for download at
https://resources.oreilly.com/examples/0636920064602.
This book is here to help you get your job done. In general, if example code is offered
with this book, you may use it 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 2: Up and Running by Brent
Laster (O’Reilly). Copyright 2018 Brent Laster, 978-1-491-97959-4.”
If you feel your use of code examples falls outside fair use or the permission given
above, feel free to contact us at permissions@oreilly.com.
IMPORTANT NOTE ABOUT CODE EXAMPLES IN THIS
BOOK
In many cases where code listings occur in the book, individual lines of the code are
too long to fit in the printed space. In those cases, the code is wrapped around and
continued on the next line(s). There are generally not line continuation characters on
these lines. However, you can usually tell where code has been continued from the