Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy 如何在并行任务失败时执行工作流_Groovy_Jenkins_Continuous Integration_Jenkins Workflow - Fatal编程技术网

Groovy 如何在并行任务失败时执行工作流

Groovy 如何在并行任务失败时执行工作流,groovy,jenkins,continuous-integration,jenkins-workflow,Groovy,Jenkins,Continuous Integration,Jenkins Workflow,我有以下工作流程: def flow node('envinf1') { def buildTasks = [:] for(i = 0; i < 2; i++) { buildTasks[i] = { sh 'some command which fails in one of the tasks' } } parallel buildTasks echo 'Some message!' }

我有以下工作流程:

def flow
node('envinf1')
{
    def buildTasks = [:]
    for(i = 0; i < 2; i++) {
        buildTasks[i] = {
            sh 'some command which fails in one of the tasks'
        }
    }
    parallel buildTasks
    echo 'Some message!'
}
def流量
节点('envinf1')
{
def buildTasks=[:]
对于(i=0;i<2;i++){
构建任务[i]={
sh“某个命令在某个任务中失败”
}
}
并行构建任务
回音“一些信息!”
}
当其中一个任务失败时,工作流永远不会到达
echo…
-行,而是整个作业失败,出现异常:


org.jenkinsci.plugins.workflow.cps.steps.ParallelStepException:并行步骤0失败
位于org.jenkinsci.plugins.workflow.cps.steps.ParallelStep$ResultHandler$Callback.checkAllDone(ParallelStep.java:153)
...

是否可以告诉
并行
-步骤继续执行工作流脚本

buildTasks[i] = {
    try {
        sh 'some command which fails in one of the tasks'
    } catch (e) {
        echo "got ${e} but continuing…"
    }
}
如果希望构建最终失败,可以使用
catchError
步骤

buildTasks[i] = {
    catchError {
        sh 'some command which fails in one of the tasks'
    }
}
或者用手写出等价物

buildTasks[i] = {
    try {
        sh 'some command which fails in one of the tasks'
    } catch (e) {
        echo "failed with ${e}"
        currentBuild.result = 'FAILURE'
    }
}
catchError
确实比手工构建的同类产品有一个优势:它通过打印单行消息来处理
AbortException
(例如,来自
sh
的非零退出代码),
FlowInterruptedException
(例如,用户单击停止按钮)通过打印“abortby…”来处理
AbortException消息和设置自定义结果(如
中止
),以及通过打印堆栈跟踪执行的所有其他操作