In case you want to always see the error when the command fails:
```
task myCommandLineTask(type: Exec) {
commandLine 'my_command.sh'
ignoreExitValue = true
standardOutput = new ByteArrayOutputStream()
doLast {
def exitCode = executionResult.get().exitValue
if (exitCode != 0) {
def result = standardOutput.toString()
logger.warn(result)
throw new GradleException("Failed to run command (exit code:$exitCode)")
}
}
}
```
Here is what I am using for newer version of gradle:
```
task myCommandLineTask(type: Exec) {
commandLine 'my_command.sh'
ignoreExitValue = true
standardOutput = new ByteArrayOutputStream()
doLast {
def exitCode = executionResult.get().exitValue
if (exitCode != 0) {
def result = standardOutput.toString()
println result
throw new GradleException("Failed to run command (exit code:$exitCode)")
}
}
}
```