groovy 是否停止替代/跳过并行Jenkins作业?

ohtdti5x  于 2022-12-11  发布在  Jenkins
关注(0)|答案(2)|浏览(184)

我正在运行一个Jenkins作业,我调用另一个Jenkins作业来构建Azure环境。
我创建了一个二维数组[:],并在其中存储了3个作业。
当我在数组上调用关键字“parallel”时,3个作业应该并行运行。这对我过去所有的Jenkins文件都有效,但当我在这里运行它时,它只运行三个作业中的一两个。

node(label: 'master')
{
    def branches = [:]

    stage ('Parallel Builds')
    {
        for (int i = 0; i < 3; i++) 
        {
            branches["branch${i}"] = prepare(i)
        }
        
        echo "branches: ${branches}"
        parallel branches
    }

}

def prepare(def num)
{
    return {
            build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                                                                [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snap-win10-19.6.9-boh-cfc-qs'],
                                                                                [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-'+num]
                                                                                ]
    }
}

Jenkins console - skipping job when running in parallel
我期待所有的并行作业一起运行,但它一直跳过一两个。
编辑:我还为失败的分支实现了重试(3),但失败的作业只是无限地挂起...下面是重试代码以及Jenkins控制台的图片...
Jenkins console - jobs that fail hang

node(label: 'master')
{
    def branches = [:]
    branches.failFast = false

    stage ('Parallel Builds')
    {
        for (int i = 0; i < 3; i++) 
        {
            branches["branch${i}"] = prepare(i)
        }
        
        echo "branches: ${branches}"
    }
    
    
    try 
    {    
        parallel branches
    }
    catch(Exception e) 
    {
        e.getCauses().each 
        {
            echo "${it.getShortDescription()}"
        }
    }

}

def prepare(def num)
{
    return {
        try
        {
            build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                    [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snapPOSQSWithEDC1.2'],
                                    [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-0-PARALLEL-'+num],
                                    [$class: 'StringParameterValue', name:'ResourceGroupName', value: 'rg-aloha-pos-automation']
                                    ]
            
        }
        catch(error) 
        {
            echo "First build failed, let's retry if accepted"
            retry(3) 
            {
                input "***Retry the job***"
                build job: 'Azure/Environment-General/Environment - Create', parameters: [
                                    [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snapPOSQSWithEDC1.2'],
                                    [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                    [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-PARALLEL-'+num],
                                    [$class: 'StringParameterValue', name:'ResourceGroupName', value: 'rg-aloha-pos-automation']
                                    ]
            }  
        }
    }
}
4xrmg8kj

4xrmg8kj1#

尝试将propagate: false添加到生成命令。

build job: 'Azure/Environment-General/Environment - Create', propagate: false, parameters: [
                                                                                [$class: 'StringParameterValue', name: 'BOHSnapshotName', value: 'snap-win10-19.6.9-boh-cfc-qs'],
                                                                                [$class: 'StringParameterValue', name:'Terminal1SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'Terminal2SnapshotName', value: 'none'],
                                                                                [$class: 'StringParameterValue', name:'EnvironmentPrefix', value: 'jl250638-'+num]
dkqlctbz

dkqlctbz2#

找到了一个非常愚蠢的解决方案.....我调用的作业将参数"不允许并发构建“取消选中......我取消选中,并行工作正常。
会继续这样做,以防万一有人也犯这个错误,哈哈

相关问题