2017-08-16 112 views
1

This guy seems to have the same problem如何讓xunit停止jenkins管道失敗?

下面是我在做什麼:

stage('Test') { 
     steps { 
      bat "\"${tool 'VSTestRunner'}\" %WORKSPACE%\\MyApp\\bin\\Debug\\MyApp.dll /logger:trx & exit 0" 
      // The test publish is responsible for decided whether the test stage failed 
      step([$class : 'XUnitPublisher', 
       testTimeMargin: '3000', 
       thresholdMode: 1, 
       thresholds: [ 
        [$class: 'FailedThreshold', failureNewThreshold: '', failureThreshold: '1', unstableNewThreshold: '', unstableThreshold: ''], 
        [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: ''] 
       ], 
       tools : [[$class: 'MSTestJunitHudsonTestType', 
        deleteOutputFiles: true, 
        failIfNotNew: false, 
        pattern: "TestResults\\*.trx", 
        skipNoTestFiles: false, 
        stopProcessingIfError: true 
       ]] 
      ]) 

     } 
    } 

如果測試失敗管道仍在繼續。

我希望能夠通過xunit設置來控制管道是否繼續。有沒有比這更優雅的方式:

if (currentBuild.result.equals("FAILURE")) { 
    throw "Test results did not pass thresholds" 
} 

此外,「stopProcessingIfError」是做什麼的?我認爲如果超過了錯誤閾值,它會停止管道,但事實並非如此。 xunit服務有沒有這樣做的參數?

+0

通常,如果你想失敗一個構建,你必須拋出退出狀態!= 0 – OK999

+0

我有什麼錯誤級別可用於我?只是失敗,成功和不穩定? – red888

回答

1

FAILED,SUCCESS和UNSTABLE是jenkins的狀態,而不是退出狀態。退出狀態應該來自正在執行的進程。因此,如果測試失敗,您的解決方案是設置exit 1(或非零)。您的批處理步驟似乎設置了出口0.請檢查ERRORLEVEL,因爲您似乎在窗口中,並且如果其非零,則通過強制退出1從管道中突然跳出注:它可以(我指的是退出代碼中的1)

+0

這對我來說更有意義。 xunit正確地設置了構建狀態,並且該進程沒有錯誤地退出,所以它「成功」,然後在那一刻它就由我來讀取構建狀態並決定我是否希望管道失敗。 – red888