jenkins the definitive guide

(Jeff_L) #1

and running your unit tests. Or you might want a build job to do other related tasks, such as running your
integration tests, measuring code coverage or code quality metrics, generating technical documentation,
or even deploying your application to a web server. A real project usually requires many separate but
related build jobs.


Our sample application is a simple Java implementation of John Conway’s “Game of Life.”^16 The Game
of Life is a mathematical game which takes place on a two dimensional grid of cells, which we will
refer to as the Universe. Each cell can be either alive or dead. Cells interact with their direct neighbors
to determine whether they will live or die in the next generation of cells. For each new generation of
cells, the following rules are applied:



  • Any live cell with fewer than two live neighbors dies of underpopulation.

  • Any live cell with more than three live neighbors dies of overcrowding.

  • Any live cell with two or three live neighbors lives on to the next generation.

  • Any dead cell with exactly three live neighbors becomes a live cell.


Our application is a Java module, built using Maven, that implements the core business logic of the
Game of Life. We’ll worry about the user interfaces later on. For now, let’s see how we can automate
this build in Jenkins. If you are not familiar with Maven, or prefer Ant or another build framework—
don’t worry! The examples don’t require much knowledge of Maven, and we’ll be looking at plenty of
examples of using other build tools later on in the book.


For our first build job, we will keep it simple: we are just going to compile and test our sample
application. Click on the New Job link. You should get to a screen similar to Figure 2.14, “Setting up
your first build job in Jenkins”. Jenkins supports several different types of build jobs. The two most
commonly-used are the freestyle builds and the Maven 2/3 builds. The freestyle projects allow you to
configure just about any sort of build job: they are highly flexible and very configurable. The Maven
2/3 builds understand the Maven project structure, and can use this to let you set up Maven build jobs
with less effort and a few extra features. There are also plugins that provide support for other types of
build jobs. Nevertheless, although our project does use Maven, we are going to use a freestyle build job,
just to keep things simple and general to start with. So choose “Build a freestyle software project”, as
shown in Figure 2.14, “Setting up your first build job in Jenkins”.


You’ll also need to give your build job a sensible name. In this case, call it gameoflife-default, as it will
be the default CI build for our Game of Life project.


(^16) See http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life.

Free download pdf