Build script: how can I tell that a gradle task fails?


I maintain a build-script (batch file), and this file invokes gradle tasks:

call gradle clean build

after this call, there are other things that should occur - but only if the build was successful. The problem is that when gradle fails - for example when ‘clean’ task fails, i see errors in the command line, but the batch file keeps going.

The question: how can I query whether the gradle tasks were successful or not?


The problem described sounds like the normal, expected behavior when using the call command in a batch script. Whether you’re calling Gradle or basically anything else, you need to check the exit code of the previous command if you care whether it was successful or not.

You won’t really be querying Gradle for anything as the procedure for accessing the exit code depends on the environment you’re running in. For a batch file, you should be looking for the value in errorlevel. If you need additional details or examples, this site should help:

1 Like

%errorlevel% indeed is what i was looking for :smile: