Windows Jobs running a .bat not failing when they should
search cancel

Windows Jobs running a .bat not failing when they should

book

Article ID: 204921

calendar_today

Updated On:

Products

CA Automic Workload Automation - Automation Engine

Issue/Introduction

Windows Jobs are not failing/aborting when a jobs abends, it shows completed successfully in Automic:
Expected behavior: Job ends with ENDED_NOT_OK and non-0 return code
Actual behavior: Job ends with ENDED_OK and return code 0

The Windows job is running a .bat script that references %ERRORLEVEL%

Environment

Release : 12.3

Component : AUTOMATION ENGINE

Cause

Since the Windows job itself runs a .bat file (Oxxxxxxxx), that .bat file ended with a non-0 ret code even though the .bat that the O*bat called did not end with a non- ret code.

Resolution

The windwos job was calling a .bat script that had the following lines in it:


set %exit_code%=%ERRORLEVEL%
if %exit_code% EQU 0 (
    echo Successfully executed job
    echo return code = %exit_code%
)

if %exit_code% NEQ 0 (
    echo Error executing job
    echo return code = %exit_code%
)


In order to resolve the issue, the code in the .bat file was changed to:


set %exit_code%=%ERRORLEVEL%
if %exit_code% EQU 0 (
    echo Successfully executed job
    exit %exit_code%
)

if %exit_code% NEQ 0 (
    echo Error executing job
    exit %exit_code%
)




Once that change was put into place, the job was able to run the way it was expected to run.