Audit your jobs for compatibility with High Availability (active/active)

Audit jobs for High Availability (HA) compatibility. Pipeline builds can resume after a controller restart or agent disconnection, but Freestyle and Maven builds aren't adopted by another replica. Review the required Default Speed/Durability Level setting, and emulate the HA-incompatible `build` and `lock` Pipeline steps where needed.

5 minute read

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:

  • Running builds can continue to run even after a controller restarts and can succeed after it resumes. This includes running sh, bat, or powershell steps. The same mechanism would allow replicas to adopt builds in HA controllers when a replica is shutting down due to a failure or during a rolling restart or rolling upgrade.

  • sh, bat, and powershell steps in builds can survive temporary agent disconnections. As long as the agent continues running during the disconnections, the step and the build can succeed. HA controller replicas adopt and load balance the running builds, with agents able to roam between replicas. Any replica can resume and continue a build. Builds can even survive agent failures using the Retry option.

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 Maximum survivability/durability but slowest.

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:

Pipeline policy rule for pipeline idioms or steps incompatible with HA
Figure 1. Pipeline policy rule for pipeline idioms or steps incompatible with HA

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:

  1. Select in the upper-right corner to navigate to the Manage Jenkins page.

  2. Select Cloudbees CI High Availability

  3. Select Configure in the left pane.

  4. For Pipeline build step, select Emulate.

  5. Select Save or Apply.

If build step emulation is enabled, administrators can uninstall the Pipeline: Build Step plugin, and the Pipeline idioms incompatible with Cloudbees High Availability policy, if set, does not flag usages of build. The Pipeline: Build Step plugin also provides the waitForBuild step, which is not supported by the emulation.

Emulation does not support all the build step options:

  • Parameter types are limited to string, booleanParam, and text.

  • When using the propagate: true option (the default value), the not built and aborted statuses from the downstream job are treated as failures in the upstream job.

  • When using the wait: true option (the default value), only number, result, and displayName properties are supported in the step result.

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 label, quantity, or variable options, you must install the Lockable Resources plugin on the controller. The other emulation options do not require the plugin, so you can uninstall it if no Pipeline uses label, quantity, or variable. For the plugin’s HA compatibility status, refer to Non-CAP plugin compatibility for High Availability (active/active) controllers.

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 lock step, nor other functions of the Lockable Resources plugin outside of the lock step.

Table 1. Options supported by the emulated lock step
Option Description

resource

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.

label

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 Manage Jenkins  Lockable Resources.

The Lockable Resources page displays only the configured resources, but does not display the actual lock status. To review which builds hold and wait for locks, refer to View the status of locks.

quantity

The number of resources with the specified label to lock. Only a value of 1 is supported.

variable

The name of an environment variable that receives the locked resource name while the block runs. Use this option with label to find out which resource the step locked.

skipIfLocked

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.

inversePrecedence

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:

  1. Select in the upper-right corner to navigate to the Manage Jenkins page.

  2. Select Cloudbees CI High Availability

  3. Select Configure in the left pane.

  4. For Pipeline lock step, select Emulate.

  5. Select Save or Apply.

If lock step emulation is enabled, the Pipeline idioms incompatible with Cloudbees High Availability policy, if set, does not flag usages of lock.

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:

  1. Select in the upper-right corner to navigate to the Manage Jenkins page.

  2. Select Cloudbees CI High Availability

  3. 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 label pool appears under every resource it is queued on.