How to conditionally fail fast from tests?

I have been trying to come up with a way to conditionally stop test execution, similar to --fail-fast, but so far no luck.

I think this describes what I’m trying to accomplish (but does not work):

    afterTest { desc , result ->
        if (result.resultType == TestResult.ResultType.FAILURE) {
            if (result.failures[0].rawFailure.message == "some keyword") {
               throw some exception

Is there some way to accomplish this?