在循环 Jenkins 管道中设置 quietPeriod

Set quietPeriod in cycle Jenkins pipeline

我有这个管道脚本:

node{
    String[] testNames = ["A", "B", "C"]
    def tests = [:]
    for ( int i = 0; i < testNames.size(); i++ )
    {
        def testJobName = testNames[i]
        tests[testJobName] =
        {
            build job: testJobName, quietPeriod: 10*i
        }
    }
    parallel tests
}

我需要为循环中的每个作业设置不同的静默期。在这种情况下:作业 A 为 0 秒,作业 B 为 10 秒,作业 C 为 20 秒。作业 A、B 和 C 应并行启动:作业启动,作业 B 等待 10 秒并启动,С 作业B 开始后等待 10 秒(从最开始开始 20 秒)并开始。取而代之的是,所有构建都等待 30 秒,然后同时开始。请帮忙。谢谢

这似乎是 groovy 带有循环计数器的闭包语言规范。 一种可能的解决方法是像这样在闭包之外设置周期变量:

node{
    String[] testNames = ["A", "B", "C"]
    def tests = [:]
    for ( int i = 0; i < testNames.size(); i++ )
    {
        def testJobName = testNames[i]
        int period = i*10
        tests[testJobName] =
        {
            build job: testJobName, quietPeriod: period
        }
    }
    parallel tests
}

您可以在这里看到更详细的答案: