Here is an exec task set up in a pretty default way, something like:

task myTask(type:Exec) {

    workingDir '.'

    commandLine './myscript.sh'

    ignoreExitValue true

    doLast {
        if(execResult == 0) {
           //one thing
        } else {
           //another thing
        }
    }
}

Use ignoreExitValue = true so that task will not fail even script returns non-zero value.