jenkins the definitive guide

(Jeff_L) #1

jobs should strive to be as independent as possible, but sometimes this can be difficult. For example,
different build jobs may need to access the same test database or files on the hard disk, and doing so
simultaneously could potentially compromise the results of the tests. Or a performance build job may
need exclusive access to the test server, in order to have consistent results each time.


The Locks and Latches plugin lets you get around this problem to some extent. This plugin lets you set
up “locks” for certain resources, in a similar way to locks in multithreaded programming. Suppose, for
example, in the build jobs depicted in Figure 10.33, “A more complicated build job dependency graph”,
that the load tests and the performance tests run against a dedicated server, but only one build job can
run against this server at any one time. Imagine furthermore that the performance tests for other projects
also run against this server.


To avoid contention over the performance server, you could use the Locks and Latches plugin to set up
a “lock” reserving access to this server to a single build job at a time. First, in the System Configuration
page, you need to add a new lock in the Locks section (see Figure 10.34, “Adding a new lock”). This
lock will then be available to all build jobs on the server.


Figure 10.34. Adding a new lock


Next, you need to set up each build job that will be using the contended resource. In the Build
Environment section, you will find a Locks field. Tick the checkbox and select the lock you just created
(see Figure 10.35, “Configuring a build job to use a lock”). Once you do this for each of the build jobs
that need to access the resource in question, only one of these build jobs will ever be able to run at a
given time.


Figure 10.35. Configuring a build job to use a lock


10.7. Build Pipelines and Promotions


Continuous Integration is not just about automatically building and testing software, but can also help in
the broader context of the software product development and release life cycle. In many organizations,

Free download pdf