Execute finalizedBy even if task fails


(Jean-Baptiste Nizet) #1

Not sure if I should post this as an idea or as a bug.

I have an integration test task depending on a cargoStartLocal task to start a tomcat server, and finalized by a cargoStopLocal task to stop this tomcat server once the tests have been executed. The integration test task consists in setting up and populating a test database and in using Exec tasks to run tests using NodeJS:

task re2eWithServer(type: GruntTask) {

description = ‘Creates the war, start a server, creates the integration schema and populates it, then runs the re2e tests and stops the server.’

group = ‘End-to-end tests’

dependsOn war

dependsOn liquibaseDropAllInteg

dependsOn liquibaseUpdateInteg

dependsOn populateIntegDatabase

dependsOn ‘cargoStartLocal’

finalizedBy ‘cargoStopLocal’

gruntArgs = ‘re2e’

}

Unfortunately, if one of the Exec tasks executed after the cargoStartLocal has been executed fails, the build stops and the cargoStopLocal task is not executed. This leaves a Tomcat process running, and makes the next build fail since Tomcat is already running.

It would be nice if the finalizedBy task was executed even in case of a failure in the task.


(René Groeschke) #2

Hello the finalizedTask is executed even if the task its finalizing is failing. But it does not work transitively. You would need to to add a finalizedBy block to your exec tasks too to get your setup working correctly.

cheers, René


(Perryn Fowler) #3

Hi jnizet,

To add to what Rene said, I think you probably actually want to do something like

cargoStartLocal.finalizedBy('cargoStopLocal')

because, after all, cargoStop is the other half of cargoStart.

Then you can try

cargoStopLocal.mustRunAfter('re2eWithServer')

to make sure cargoStop waits for the e2e tests to finish


(Jean-Baptiste Nizet) #4

Thanks to both of you. I understand how it works now, and managed to make it work fine.