在cycle Jenkins管道中设置quietPeriod

在cycle Jenkins管道中设置quietPeriod,jenkins,groovy,jenkins-plugins,jenkins-pipeline,Jenkins,Groovy,Jenkins Plugins,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, q

我有以下管道脚本:

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
}
节点{
字符串[]testNames=[“A”、“B”、“C”]
def测试=[:]
对于(int i=0;i

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

这似乎是带循环计数器的闭包的groovy语言规范。 一种可能的解决方法是将period变量从闭包中设置出来,如下所示:

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
}
节点{
字符串[]testNames=[“A”、“B”、“C”]
def测试=[:]
对于(int i=0;i

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

这似乎是带有循环计数器的闭包的groovy语言规范。 一种可能的解决方法是将period变量从闭包中设置出来,如下所示:

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
}
节点{
字符串[]testNames=[“A”、“B”、“C”]
def测试=[:]
对于(int i=0;i
您可以在此处看到更详细的答案: