(imported comment written by MattPeterson)
That’s what I was thinking the problem was. It seems if you have download statements (or prefetch) in your action the client evaluates all “if” statements prior to running. The exit code of the action obviously wouldn’t exist until after the action was running. So I added an “if exist exit code of action then else” statement and was able to get this to work. One thing to mention is even though the client evaluates the if statements (and parameters) prior to running the action, it will evaluate them again during the action. So in my case the exit code parameter is evaluated prior to running, and must not contain errors, however it will evaluate again when that line is reached in the action, so the correct exit code is set. I used parameters for the exit code in order to retrieve it in the console in the event of failure, example below.
waithidden run.cmd
parameter “Exitcode” = “{if exist exit code of action then exit code of action as string else “52311”}”
if {parameter “Exitcode” != “0”}
//Run.cmd did not complete as expected. Now run run2.cmd and exit the task with the exit code from run.cmd
Waithidden run2.cmd
exit {parameter “Exitcode”}
endif