7
votes

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?

1
Have you found a solution in the meantime? - nogenius
@nogenius I have not found the solution to the throttling problem, but I have implemented a solution to the broader database collision problem: Every job creates a new database with a random name, configures the code to use that database, and then deletes the database in the post { always {} } step of the pipeline. This has the added benefit of allowing multiple jobs to execute concurrently while maintaining resource separation. - amacrobert
What a pitty (for me) - good for you though. Glad you found a solution - nogenius

1 Answers

7
votes

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)