A similar question was raised in Finalizer tasks that depend on the base task do not execute if the base task fails, but I have a different use case.
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.')
perfTest.finalizedBy 'collectLogs'
What I want to do here is to collect logs even if performance testing fails. So, I used finalizedBy
and was puzzled about why in the world it was not working on failures. After some poking, I figured that it is not working because the failure actually occurs in the dependent jmRun
task. So, the fix is this:
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.')
jmRun.finalizedBy 'collectLogs' // Have to finalize jmRun rather than perfTest
This is OK, but a bit not what I expected from finalizedBy
. I expected sort-of try/finally
functionality for perfTest
task. Is a defect in order?