2017-08-08 8 views
2

私はジェンキンスパイプラインのジョブで使用されるジェンキンススクリプトを、持っている:Jenkinsfile並列分岐して複数の例外を捕捉するためにどのように

try{ 
    parallel branch1: { 
     //some function that may throw exception 
    }, branch2: { 
     //some function that may throw exception 
    }, branch3: { 
     //some function that may throw exception 
    } 
}catch(Exception e){ 
    //gather the error information together (if there 1 error then just it, if there are 2 errors then concatenate 2 errors together, etc) and print it. 
} 

はどうすればこれを行うことができますか?または私はこれを行うことはできません?

答えて

0

何らかのエラーが変数に含まれていても、それをキャプチャして出力をキャプチャし、最終ステージに格納すると仮定します。それでは、ステージごとのビルド結果を成功として設定して、ジョブが早期に失敗しないようにするだけです。その方法については、this questionを参照してください。最後に、変数を最後に連結します。

最終的な結果は(半疑似コード)のように見えます。

try{ 
    parallel branch1: { 
     //some function that may throw exception 
     error1=$(echo error) 
     currentBuild.result = 'SUCCESS' 
     return 
    }, branch2: { 
     //some function that may throw exception 
     error2=$(echo error) 
     currentBuild.result = 'SUCCESS' 
     return 
    }, branch3: { 
     //some function that may throw exception 
     error3=$(echo error) 
     currentBuild.result = 'SUCCESS' 
     return 
    } 
}catch(Exception e){ 
    //gather the error information together (if there 1 error then just it, if there are 2 errors then concatenate 2 errors together, etc) and print it. 
    print $error1 + $error2 + $error3 
} 

私ものtry/catchの外にそれを取るとちょうどエラーを処理するために、あなたのcurrentBuild.resultの設定に依存しているかもしれません。

関連する問題