How to get a Server Agent Job to report Failure?

  • Here is my problem! I have several multi-step jobs that run overnight. For example, Step1 Setup; Step2 Admin Tasks; Step 3 Taks Failed; Step 4 Cleanup. If Step2 completes Ok it goes to Step 4, if Step2 Fails Step3 sends an alert message to the standby operator. This all works fine!!

    Only issue is the job completes reporting success. How can I get the job to report Failure if one step fails (so that the job icon changes to the red X!!)??

    Regards, Ian Scott

     

  • If I understand you correctly, what you are looking for can be accomplished by editing the job steps from Enterprise Manager. Under the Advanced tab, you can dictate whether the job continues or stops if the step fails.

  • For step three, in the "On success action" set it to quit the job reporting failure.

     

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • OK, I will attempt to explain this a little better!

    It is essential that Step4 (Cleanup) is the last step executed. Step2 is set for On Success Step4, On Failure Step3 (Send Email) then Step4. Problem is the job completes reporting Success even though Step2 has failed.

    Irrespective of the number of steps and the execution order, it would be nice to be able to force the job to report Failure when any step fails (or change the job icon to the red X!)

    Regards, Ian Scott

  • Add a step5 that does identical work as step4.  For step4, make it report failure, on both success and failure.  Modify step2 to go to step5 on success.

    This is success:

    Step1 -> Step2 -> Step5  Reports success

    This is a failure

    Step1 -> Step2 -> Step3 -> Step4 Reports failure

     

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

  • Thanks Kathi,

    Your previous reply put me on the right path. The classic case of tunnel vision from thinking about this for too long!!

    Regards, Ian Scott

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply