3

我正在使用 Jenkins 的 Phing 构建脚本,并希望在作业中端到端运行它并捕获所有报告。问题是它停止构建失败的构建步骤。有没有办法或插件即使在失败时也能继续工作?

谢谢

4

2 回答 2

1

I don't know a lot about Phing but, since it's based on Ant, if the build step you are executing has a "failonerror" attribute you should be able to set it to false so that the entire build doesn't fail if the step returns an error.

于 2012-05-02T20:50:25.337 回答
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 命令运行这些测试,请考虑使用“|| true”后缀运行 sh 脚本,这会告诉 linux sh 脚本以结果代码 0 退出,即使您的实际命令以 exit 退出代码。

例子:

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
于 2017-01-02T09:15:42.630 回答