Blocking/Locking without executors

Jenkins setup: Version 2.479.1, Kubernetes

Hi everyone… I’m currently using the build-blocker plugin. That works well, except you can only set a single blocking mode so it’s somewhat limited. I need to block on multiple levels, so I attempted to use the lockable-resources plugin. The problem there is if I run 10 executors, with 10 jobs waiting on the same lock, all 10 executors will be busy and blocking other jobs. The locks aren’t evaluated until after the pipeline begins executing. Anyone know of any way to block jobs other than the build-blocker plugin that doesn’t consume executors?

If you’re looking to manage job blocking in Jenkins without hogging executors, the Throttle Concurrent Builds plugin is a super handy tool. It lets you control the number of concurrent builds either within a single project or across multiple projects. Here’s a straightforward guide on setting it up:

Step 1: Install the Throttle Concurrent Builds Plugin

  • Head over to Manage Jenkins → Plugins.
  • Click on Available Plugins.
  • Find the Throttle Concurrent Builds in the search bar and install it.

Step 2: Configure Throttling for a Job

  • Jump into the configuration page of the job you want to throttle.
  • Scroll to the Throttle Concurrent Builds section.
  • Enable the Throttle this project as part of one or more categories option.
  • Here, you can either create a new category or select an existing one to use.
  • Set the Maximum Total Concurrent Builds and Maximum Concurrent Builds Per Node according to your need.

Step 3: Apply Throttling Across Multiple Jobs

  • If you’d like to extend throttling settings to multiple jobs, just assign the same category to each job.

Here’s a quick example of how you can tweak a Jenkins pipeline to utilize the Throttle Concurrent Builds plugin:

pipeline {
    agent any
    options {
        throttleConcurrentBuilds(
            maxTotal: 2, // Maximum total concurrent builds
            maxPerNode: 1, // Maximum concurrent builds per node
            categories: ['my-throttle-category'] // Throttle category
        )
    }
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                // Your build steps here
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
                // Your test steps here
            }
        }
    }
}

Explanation:
Throttle Concurrent Builds: The throttleConcurrentBuilds option is used to limit the number of concurrent builds.
maxTotal: The maximum number of concurrent builds allowed across all nodes.
maxPerNode: The maximum number of concurrent builds allowed per node.
categories: The category used to group jobs for throttling.
By using the Throttle Concurrent Builds plugin, you can effectively manage job blocking without consuming executors unnecessarily.

What’s happening here?

  • Throttle Concurrent Builds: The throttleConcurrentBuilds option limits the number of concurrent builds.
  • maxTotal: Specifies the maximum allowable concurrent builds across all nodes.
  • maxPerNode: Restricts the number of concurrent builds on each node.
  • categories: Groups jobs for collective throttling customization.

By using the Throttle Concurrent Builds plugin, you’ll be better equipped to manage job blocking without unnecessarily consuming executors. Give it a shot! :person_shrugging:

Thank you for the idea, but I don’t think that’s going to do what I need it to do. I don’t care how many of each are running, but if a higher priority job is in the queue then the lower priority jobs should not run until the higher priority job is started. The other requirement is that if a global priority job needs to run (think Jenkins restart or something else affecting the environment) then no new jobs should be starting. I’m looking at using the build-blocker plugin for blocking for the global priority jobs and the priority-sorter plugin for everything else unless I find a better solution.