Here's how I managed tracking "returned state" from an SSIS package called via a SQL Agent job. If we're lucky, some of this may apply to your system.
...and then it gets messy, as you can get a host of values returned from SSIS . I logged actions and activity in a DB table while going through the SSIS steps and consult that to try to work things out (which is where @Description below comes from). Here's the relevant code and comments:
-- Evaluate the DTEXEC return code
SET @Message = case
when @ReturnValue = 1 and @Description <> 'SSIS Package' then 'SSIS Package execution was stopped or interrupted before it completed'
when @ReturnValue in (0,1) then '' -- Package success or failure is logged within the package
when @ReturnValue = 3 then 'DTEXEC exit code 3, package interrupted'
when @ReturnValue in (4,5,6) then 'DTEXEC exit code ' + cast(@Returnvalue as varchar(10)) + ', package could not be run'
else 'DTEXEC exit code ' + isnull(cast(@Returnvalue as varchar(10)), '<NULL>') + ' is an unknown and unanticipated value'
end
-- Oddball case: if cmd.exe process is killed, return value is 1, but process will continue anyway
-- and could finish 100% succesfully... and @ReturnValue will equal 1. If you can figure out how,
-- write a check for this in here.
That last references the "what if, while SSIS is running, some admin joker kills the CMD session (from, say, taskmanager) because the process is running too long" situation. We've never had it happen--that I know of--but they were uber-paranoid when I was writing this so I had to look into it...