Jenkins workspaces and concurrent builds, how do they work?

Viewed 8902

I am currently learning the ins and outs of Jenkins and Pipeline. One thing I do not yet understand is the following:

A Jenkins job by default can be executed concurrently (I can check the checkbox "Do not allow concurrent builds" if I don't want that).

What I don't understand is the following: Let say Jenkins checks out code in /var/lib/jenkins/workspace/my-project-workspace/

Now how would it be possible to run concurrent builds without conflicts? Let's say that build nr 1 checks out code in that path and starts testing it, and while doing that, build nr 2 is started and checks out code in that same path. How will that not conflict with build nr 1? I am probably missing something obvious here... Please help :)

2 Answers

When this option is checked, multiple builds of this project may be executed in parallel.

By default, only a single build of a project is executed at a time — any other requests to start building that project will remain in the build queue until the first build is complete. This is a safe default, as projects can often require exclusive access to certain resources, such as a database, or a piece of hardware.

But with this option enabled, if there are enough build executors available that can handle this project, then multiple builds of this project will take place in parallel. If there are not enough available executors at any point, any further build requests will be held in the build queue as normal.

Enabling concurrent builds is useful for projects that execute lengthy test suites, as it allows each build to contain a smaller number of changes, while the total turnaround time decreases as subsequent builds do not need to wait for previous test runs to complete. This feature is also useful for parameterized projects, whose individual build executions — depending on the parameters used — can be completely independent from one another.

Each concurrently executed build occurs in its own build workspace, isolated from any other builds. By default, Jenkins appends "@" to the workspace directory name, e.g. "@2". The separator "@" can be changed by setting the hudson.slaves.WorkspaceList Java system property when starting Jenkins. For example, "hudson.slaves.WorkspaceList=-" would change the separator to a hyphen. For more information on setting system properties, see the wiki page.

However, if you enable the Use custom workspace option, all builds will be executed in the same workspace. Therefore caution is required, as multiple builds may end up altering the same directory at the same time. enter image description here

Related