Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Throttle Concurrent Builds in Jenkins Declarative Pipelines

I have Jenkins declarative pipelines for a few different repos that trigger a database refresh, and unit tests that depend on the database. These Jenkins jobs are triggered from pull requests in GitHub.

To avoid resource collisions, I need to prevent these jobs from running at the same time -- both within each project, and across projects.

The "Throttle Concurrent Builds" plugin seems to be built for this.

I have installed the plugin and configured a category like so:

TCB system configuration

And I added the "throttle" option to the Jenkinsfile in one of the repositories whose builds should be throttled:

pipeline {

    agent any

    options {
        throttle(['ci_database_build'])
    }

    stages {
        stage('Build') {
            parallel {
                stage('Build source') {
                    steps {

                        // etc etc...

However, this does not seem to be preventing 2 jobs from executing at once. As evidence, here are 2 jobs (both containing the above Jenkisfile change) executing at the same time:

Two throttled jobs running at the same time

What am I missing?

like image 669
amacrobert Avatar asked Mar 24 '20 22:03

amacrobert


1 Answers

The following in the options block should work

options {
    throttleJobProperty(
        categories: ['ci_database_build'],
        throttleEnabled: true,
        throttleOption: 'category',
    )
}

The full syntax can be seen here: https://github.com/jenkinsci/throttle-concurrent-builds-plugin/pull/68)

like image 127
nogenius Avatar answered Oct 15 '22 00:10

nogenius