如何限制詹金斯声明管道中的矩阵配置

How to throttle matrix configurations in Jenkins declarative pipeline

我需要限制 Jenkins 声明管道中的 Matrix 配置。现在我有一个像这样的简单矩阵:

    matrix {
      axes {
        axis {
          name 'Test'
          values 'Example1','Example2','Example3'
        }
      }
    }

而我运行只能并行配置五个。首先我创建了一个 category:

现在我正在尝试使用节流作业 属性,但我被卡住了。如我所见 here 为了使用油门矩阵配置,我们需要传递 matrixOptions 包含两个属性 throttleMatrixBuildsthrottleMatrixConfigurations.

的参数
    options {
           throttleJobProperty(
           categories: ['ForTestMatrix'],
           throttleEnabled: true,
           throttleOption: 'category',
           matrixOptions: ???
           )
    }

有人能告诉我如何将具有两个属性的对象作为参数传递给那里吗?

UPD 我设法 运行 这样的代码:

    options {
           throttleJobProperty(
           categories: ['ForTestMatrix'],
           throttleEnabled: true,
           throttleOption: 'category',
           matrixOptions: new hudson.plugins.throttleconcurrents.ThrottleMatrixProjectOptions(false, true)
           )
    }

但是当我开始这项工作时,我在蓝色海洋中看到所有矩阵配置同时开始。有谁知道节流为什么不能正常工作?

参见Throttle Concurrent Builds

Unsupported use cases

This section contains links to the use cases which are not supported.

Throttling of code blocks without a node() definition

...

Throttling Pipeline via job properties

Starting in throttle-concurrents-2.0, using this option is not recommended. Use the throttle() step instead.

以下管道:

pipeline {
    
    agent any

    stages {
        stage('Matrix') {
            matrix {
                axes {
                    axis {
                        name 'Example'
                        values 'Example 1','Example 2','Example 3'
                    }
                }
                stages {
                    stage('Test') {
                        steps {
                            throttle(['ForTestMatrix']) {
                                node( 'master' ) {
                                    sh 'set +x; date; sleep 5; date'
                                }
                            } // throttle
                        } // steps
                    } // stage 'Test'
                } // stages
            } // matrix
        } // stage 'Matrix'
    } // stages
} // pipeline

给出此输出:

                                 ...
[Matrix - Example = 'Example 1'] + set +x
                                 Fri Oct 22 15:54:01 GMT 2021
                                 Fri Oct 22 15:54:06 GMT 2021
                                 ...
[Matrix - Example = 'Example 2'] + set +x
                                 Fri Oct 22 15:54:06 GMT 2021
                                 Fri Oct 22 15:54:12 GMT 2021
                                 ...
[Matrix - Example = 'Example 3'] + set +x
                                 Fri Oct 22 15:54:12 GMT 2021
                                 Fri Oct 22 15:54:17 GMT 2021
                                 ...