'我正在使用net.foragerr.jmeter插件1.0.2-2.13版编写构建脚本。
我的任务主要是1)运行插件JMeter任务,2)收集应用程序日志。
task perfTest(dependsOn: ['jmClean', 'jmRun'],
description:'Runs (cleanly) performance tests on a deployed application and collects the app log if available. ' +
'Use --no-daemon to see progress. Use --info to see all JMeter command-line arguments.') << {
if (logDir.isDirectory()) {
copy {
from "${logDir}"
into "${buildDir}/jmeter-report"
include 'iRePORT.log'
}
}
}
现在,即使
jmRun
失败,我也需要收集日志。当我尝试为此实现解决方案时,我真的很困惑:jmRun
任务,因为它是一个插件任务try/finally
并直接执行其他任务,因为Gradle设计为不支持此操作,例如参见How do I wrap a gradle task in another task? --continue
标志gradle.startParameter.continueOnFailure = true
,因为它不会继续执行依赖任务我想到的唯一可能的解决方法是分离日志收集,始终将其包含在命令行中,例如
perfTest collectLogs
并在gradle.startParameter.continueOnFailure = true
中设置perfTest
。这远非理想。
有更好的解决方案吗? Gradle是否应该有一种方法来支持这样的方案?
最佳答案
您可以尝试创建这样的任务
task collectPerfTestLogs(type: Copy) {
from "${logDir}"
into "${buildDir}/jmeter-report"
include 'iRePORT.log'
}
然后有
perfTest.finalizedBy(collectPerfTestLogs)
。引用Gradle:
Finalizer tasks will be executed even if the finalized task fails.
参见https://docs.gradle.org/current/userguide/more_about_tasks.html
关于gradle - 如何拦截Gradle任务的失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34095853/