1) create trigger which store job failure information
2) you can mail or keep data in table also use you logic.
3) followinf just format to understand logic.
Create trigger [dbo].[trg_stepfailures]
on [dbo].[sysjobhistory]
for insert
as
declare @strMsg varchar(400),
if exists (select * from inserted where run_status = 0 and step_name <> '(job outcome)')
begin
select @strMsg =
convert(char(10),'Server') + char(58) + @@servername +
char(10) +
convert(char(10),'Job') + char(58) + convert(varchar(50), sysjobs.name) +
char(10) +
convert(char(10),'Step') + char(58) + convert(varchar(50), inserted.step_name)+
char(10) +
convert(char(10),'Message') + char(58) + convert(varchar(150), inserted.message)
from inserted
join sysjobs
on inserted.job_id = sysjobs.job_id
where inserted.run_status = 0
end
3) check and confirm.
-
Proposed as answer by
Dinesh Vishe
1 hour 23 minutes ago