2012-05-02 152 views
2

我正在與Jenkins一起使用Phing構建腳本,並希望在作業中端到端運行並捕獲所有報告。問題是它停止構建失敗的構建步驟。有沒有一種方法或插件可以在失敗時繼續工作?即使構建步驟失敗,如何繼續Jenkins構建?

感謝

+0

看看這有助於http://stackoverflow.com/questions/497452/subant-failonerror-subtleties –

回答

1

我不知道了很多關於Phing,但由於它是基於螞蟻,如果您正在執行的構建步驟都有一個「failonerror」屬性,你應該能夠將其設置爲false,以便如果該步驟返回錯誤,則整個構建不會失敗。

0

是,使用try,catch塊在你的腳本管道

例如:

try { 
    // do some stuff that potentially fails 
} catch (error) { 
    // do stuff if try fails 
} finally { 
    // when you need some clean up to do 
} 

或者相反,如果你使用的是sh命令來運行這些測試,考慮與「||運行你的sh腳本true「後綴,這告訴linux sh腳本以結果碼0退出,即使您的真實命令退出並退出代碼。

例如:

stage('Test') { 
    def testScript = "" 
    def testProjects = findFiles(glob: 'test/**/project.json') 

    if (!fileExists('reports/xml')) { 
     if (!fileExists('reports')) { 
      sh "mkdir reports" 
     } 
     sh "mkdir reports/xml" 
    } 

    for(prj in testProjects) { 
     println "Test project located, running tests: " + prj.path 
     def matcher = prj.path =~ 'test\\/(.+)\\/project.json' 

     testScript += "dotnet test --no-build '${prj.path}' -xml 'reports/xml/${matcher[0][1]}.Results.xml' || true\n" 
    } 

    sh testScript 
相關問題