How to execute shell script and check shell script exit code

I have very simple task that is defined below - what I am finding is the script get executed perfectly but I always get error.

Could not get unknown property ‘execResult’ for task ‘:myapp:runScriptAndCheckExitCode’ of type org.gradle.api.tasks.Exec.

My shell script exit with code 1 if there was problem, and on sucess exit with code 0. But why am I getting this issue with property execResult. I am using gradle version 8.6

task runScriptAndCheckExitCode(type: Exec) {
    String aabPath = "./someaabpath.aab"
    commandLine("/bin/sh", "-c", "./../scripts/apk-size-check.sh $aabPath") // Replace with your script and argument

    doLast {
        if (execResult.exitValue != 0) {
            throw new GradleException("Script execution failed with exit code")
        }
    }
}

For reference, same discussion on Slack: How do you execute shell script in gradle and check exit sta gradle-community #community-support