2016-11-06 21 views
1

私はユニットテストの結果を処理してページを作成ジェンキンスでそれらを表示するために、ジェンキンスパイプライン内で次の関数を使用します。ユニットテストが失敗したときに通知を送信するにはどうすればよいですか?

def check_test_results(String path) { 
    step([ 
     $class: 'XUnitBuilder', 
     testTimeMargin: '3000', 
     thresholdMode: 1, 
     thresholds: [ 
      [$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '', unstableThreshold: ''], 
      [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: ''] 
     ], 
     tools: [ 
      [$class: 'JUnitType', deleteOutputFiles: true, failIfNotNew: false, pattern: path, skipNoTestFiles: false, stopProcessingIfError: true] 
     ] 
    ]) 
} 

私はJ/xUnitの結果がで表示されていることに注意してくださいよJenkinsのページをビルドしますが、単体テストが失敗した場合にスラック通知(スラック通知は既に設定され、動作しています)を送信する機能が必要です。

答えて

2

ユニットテストスイートではtry/catchを使用できますが、おそらく個別にはありません。

def check_test_results(String path) { 
    try { 
     step([ 
      $class: 'XUnitBuilder', 
      testTimeMargin: '3000', 
      thresholdMode: 1, 
      thresholds: [ 
       [$class: 'FailedThreshold', failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '', unstableThreshold: ''], 
       [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: ''] 
      ], 
      tools: [ 
       [$class: 'JUnitType', deleteOutputFiles: true, failIfNotNew: false, pattern: path, skipNoTestFiles: false, stopProcessingIfError: true] 
      ] 
     ]) 
    } 
    catch(error) { 
     slackSend message: error 
    } 
} 

あなたの好きなようにスラック通知をカスタマイズしてください。

関連する問題