As discussed before Spring Cloud Task applications support the ability to record the exit code of a task execution.
However in cases where a user is running a Spring Batch Job within a task, regardless of how the Batch Job
Execution completes the result of the task will always be zero when using default Batch/Boot behavior.
Keep in mind that a task is a boot application and the exit code returned from
the task is the same as a boot application.
To override this behavior and allow the task to return an exit code other than zero
(either 1 the default
or based on the
ExitCodeGenerator
specified) upon a batch job returning an
ExitStatus
of "FAILED", set spring.cloud.task.batch.failOnJobFailure
to true.
This functionality does utilize a new CommandLineRunner
that replaces the one provided
by Spring Boot. By default it is configured with the same order. However, if you’d like
to customize what order the CommandLineRunner
is executed in, you can set it’s order via
the spring.cloud.task.batch.commandLineRunnerOrder
property.
To have your task return the exit code based on the result of the batch job
execution, you will need to write your own CommandLineRunner
.