仅重建失败的作业jenkins groovy管道

时间:2020-07-28 09:25:48

标签: jenkins groovy jenkins-pipeline jenkins-groovy

我有这个jenkins groovy管道,它接受多个作业名称作为参数并并行构建它们,这很好用;但是我只想为失败的作业实现重建功能,该怎么办?这是我的常规脚本

steps {
    script {
        def myparams = currentBuild.rawBuild.getAction(ParametersAction).getAllParameters().collect()
        myparams << [$class: 'NodeParameterValue',
            name: 'node',
            labels: ["${network}"],
            nodeEligibility: [$class: 'AllNodeEligibility']
        ]
        
        def jobList = [:]
        for (server in myparams) {
            if (!nonServerParams.contains(server['name']) && server['value'] == true) {
                def jobName = "${server['name'].replace('_', '-')}"
                println "Adding ${jobName} to run list"
                def paramsForBuild = retrieveOnlyValidParams(jobName, myparams.collect())
                jobList[server['name']] = {
                        def result = build job: jobName, parameters: paramsForBuild, propagate: false
                        echo "res ${result}"
                        jobResults << result
                }
            }
            if (jobList.size() > maxConcurrentNodeBuild) {
                parallel jobList
                jobList = [:]
            }
        }
        if (jobList.size() > 0)
            parallel jobList
            
        for (res in jobResults) {
            if (res.getResult() == "FAILURE") {
                currentBuild.result = "FAILURE"
            }
        }
    }
} 

0 个答案:

没有答案