1

次のワークフローがあります。

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!'
}

タスクの 1 つが失敗すると、ワークフローがecho ...-line に到達することはなく、代わりにジョブ全体が例外で失敗します。

org.jenkinsci.plugins.workflow.cps.steps.ParallelStepException: Parallel step 0 failed at org.jenkinsci.plugins.workflow.cps.steps.ParallelStep$ResultHandler$Callback.checkAllDone(ParallelStep.java:153) ...

parallel-step にワークフロー スクリプトを実行するように指示することはできますか?

4

1 に答える 1

2
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には、手作業で作成されたものよりも優れた点が 1 つあります。1行のメッセージを出力するAbortException(例: からのゼロ以外の終了コード) 、"aborted by..." メッセージを出力し、カスタム結果( など)、およびスタックトレースを出力することによるその他すべて。shFlowInterruptedExceptionABORTED

于 2015-08-28T12:19:54.660 に答える