我正在使用Jenkins和Phing构建脚本,并希望在作业中运行完整的流程并捕获所有报告。问题是,如果构建步骤失败,它会停止构建。是否有一种方法或插件可以即使在失败时也继续作业?
谢谢。
谢谢。
关于Phing,我了解得不多,但是既然它基于Ant,如果您正在执行的构建步骤具有“failonerror”属性,您应该能够将其设置为false,以便在步骤返回错误时整个构建不会失败。
是的,在你的管道脚本中使用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