ignoreExitValue is not working


(siva) #1

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


(James Justinic) #2

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'