ignoreExitValue is not working

I want the gradle task to continue even on getting exception from command line task. I’ve tried adding ignoreExitValue but its not working for me.

task createDBContainer(type: Exec) {
    workingDir '.'
    ignoreExitValue true
    commandLine "docker inspect -f {{.State.Running}} wrong_container_name"


    doLast {
        if (execResult.exitValue == 0) {
            print "Success"
        } else {
            print "Fail"
        }
        print "res is " + execResult
    }
}

I’m getting the following result

* What went wrong:
Execution failed for task ':core:createDBContainer'.
> A problem occurred starting process 'command 'docker inspect -f {{.State.Running}} wrong_container_name''

I’m using gradle 4.5

The ignoreExitValue option only controls what to do if the Exec process returns a non-zero exit code. Your task is throwing an exception before the process can even start due to incorrect usage of the API. Each part of the commandLine must be separated, not concatenated as one big String.

commandLine 'docker', 'inspect', '-f', '{{.State.Running}}', 'wrong_container_name'

The option is not working for me in version 6.7, if the command does not exist. For example, putting ‘dokcer’ instead of ‘docker’ the task fails even with ignoreExitValue true.

That’s correct. The option is not relevant in that scenario. You have to be able to execute the command before you can obtain an exit value from that specific command. The option is to specifically ignoreExitValue returned from running the command. It is not a generic ignoreFailures if you don’t provide a valid command.

Ah, ok, I understand, thanks for your reply.