Run bash script depending on finish status

Hi,
I want to be able to run one of two bash scripts depending on finish code.

I was trying to do it like, but I cannot access this tasks the tasks,
How can I exec those scripts?

gradle.buildFinished { result ->
    if (result.failure) {
        success
    } else {
        failed
    }
}

task success(type: Exec) {
    commandLine './ok'
}

task failed(type: Exec) {
    commandLine './fail'
}