Before enabling High Availability (HA), audit your jobs to understand which Pipeline capabilities support HA and which job types may need changes.
|
To get the most out of High Availability (HA) capabilities, Cloudbees recommends testing your jobs in a non-HA controller environment first. Two Pipeline capabilities are relevant to HA:
Non-Pipeline projects such as Freestyle or Maven projects run in the replica where they started. Non-Pipeline project builds are aborted when the replica running them ends for any reason, such as a rolling restart or upgrade, and no other replica can take over the build. Therefore, no HA is provided for those jobs. |
|
By default, controllers set the Default Speed/Durability Level option to This option is required in HA to allow build adoption in case of a replica failure. An administrative monitor displays if you change this option at controller level or override it at the job level. |
Even though HA is not provided for non-Pipeline projects, High Scalability (HS) can be achieved by adding more replicas to the cluster. However, if auto-scaling is enabled for Cloudbees CI on modern cloud platforms, the number of replicas can grow during periods of high workload and then shrink again once the workload returns to normal. When a scale-down removes a replica, non-Pipeline projects running on it are aborted and not adopted by other replicas.
|
The Declarative Pipeline Migration Assistant can help you migrate your Freestyle or Maven projects to Declarative Pipeline projects. |
If you plan to use controllers running in HA mode, you can define Pipeline policies.
Use these to either warn developers about those incompatible steps (Warning policy), or to prevent developers from using them (Fail policy).
The rule used for this kind of policy is Pipeline idioms incompatible with Cloudbees High Availability (active/active), as displayed in the image below:
Refer to Enforce standards with Pipeline Policies for more information about how to define and apply pipeline policies to your controller.
Emulate the build step in HA controllers
The build step, provided by the Pipeline: Build Step plugin, does not support HA.
When used, Cloudbees CI does not distribute the workloads among the replicas, and always executes the job in the replica where the build step is called.
If the upstream build is adopted, it may keep waiting indefinitely for the downstream build to finish.
Controllers running in HA mode can emulate the build step.
This emulation provides an alias for the build step with HA-compatible behavior.
This alias replaces all the Pipeline build steps in the Pipeline scripts with the build step emulation.
To enable build step emulation in a controller:
-
Select in the upper-right corner to navigate to the Manage Jenkins page.
-
Select Cloudbees CI High Availability
-
Select Configure in the left pane.
-
For Pipeline build step, select Emulate.
-
Select Save or Apply.
|
If Emulation does not support all the
|
Emulate the lock step in HA controllers
In a Pipeline, the lock step runs a block of steps while it holds a lock on a shared resource.
By default, other builds that request the same resource wait for the lock.
The lock step, provided by the Lockable Resources plugin, does not support HA.
However, controllers running in HA mode can emulate the lock step.
The emulation replaces lock steps in Pipelines with an HA-compatible alias.
|
To use the |
lock step emulation options
The lock step emulation supports the following options.
You must specify either resource or label.
|
Emulation does not support all options or behaviors of the |
| Option | Description | ||
|---|---|---|---|
|
The name of the resource to lock. Use this option to lock one specific resource. You do not need to define resource names in advance. |
||
|
The label that identifies a pool of resources. Use this option to lock one free resource from the pool. Define the pool by adding resources with labels in .
|
||
|
The number of resources with the specified label to lock.
Only a value of |
||
|
The name of an environment variable that receives the locked resource name while the block runs.
Use this option with |
||
|
By default, a build waits for the lock if another build holds it. When you set this option, the block does not run if the resource is not immediately available, and the step succeeds without acquiring the lock. |
||
|
By default, waiting builds acquire the lock in the order they requested it. When you set this option, the newest waiting build acquires the lock first. |
Examples of using the emulated lock step
Add the lock step to a Pipeline, and place the steps that need the resource inside the block.
To lock a resource by name:
lock('my-resource-name') { // your pipeline steps here }
To lock any free resource from a pool of resources that share a label:
lock(label: 'my-pool', quantity: 1, variable: 'LOCKED_RESOURCE') { // your pipeline steps here }
Enable the lock step emulation in a controller
To enable lock step emulation in a controller:
-
Select in the upper-right corner to navigate to the Manage Jenkins page.
-
Select Cloudbees CI High Availability
-
Select Configure in the left pane.
-
For Pipeline lock step, select Emulate.
-
Select Save or Apply.
|
If |
View the status of locks
When lock step emulation is enabled, the Locks page displays which builds hold and wait for each resource.
It lists every resource defined in the Lockable Resources plugin, plus resources that Pipelines lock without defining them in advance.
To view the status of locks:
-
Select in the upper-right corner to navigate to the Manage Jenkins page.
-
Select Cloudbees CI High Availability
-
Select Locks in the left pane.
For each resource, the page displays:
-
The labels, if the resource is defined in the Lockable Resources plugin.
-
The build that holds the lock, with its duration and replica.
You can abort the build that holds a lock from its row, which releases the lock. -
The builds waiting for the lock, in the order they will receive it. A build waiting on a
labelpool appears under every resource it is queued on.