2017-03-17 59 views
0

我在詹金斯管道中運行一系列階段。 每個階段代表一個測試。 即使階段(測試)失敗,我想繼續以下階段(測試),但我不知道如何。即使在失敗階段後仍繼續使用管道

我知道的唯一解決方案是用try/catch子句包含階段步驟,但這樣我就不知道測試失敗或成功了。

它們不能並行運行,它們必須按順序運行。

有沒有更好的解決方案?

相關問題:Jenkins continue pipeline on failed stage

回答

0

這是不是最佳的,因爲詹金斯不知道哪個階段都失敗了,但我們手動收集數據:

def success = 0 
    def failed = [] 

    for (int i = 0; i < tests.size(); i++) { 
     def test = tests[i] 
     stage(test) { 
      try { 
       sh "...." 
       success++ 
      } catch (e) { 
       failed << test 
      } 
     } 
    } 
    stage('Report') { 
     def failCount = tests.size()-success 
     if (failCount == 0) 
      echo "Executed ${success} tests successfully." 
     else 
      error """Executed ${success} tests successfully and ${failCount} failed: 
${failed.join(', ')}""" 
    } 
相關問題