Gradle exec task returns non-zero exit value and fails the build but I want to not fail and instead perform another task

TL;DR – Use ignoreExitValue = true

When I read the documentation for about the fiftieth time, I finally saw that there is a property, ignoreExitValue, which defaults to false. But if you set it to true, you can then perform your own tasks in the doLast block.

task myTask(type:Exec) {

    workingDir '.'

    commandLine './myscript.sh'

    ignoreExitValue true

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)