Product: PowerShell Universal
Version: 2.92
Hey PSU folks,
Let’s say I have 3 automation scripts with jobs, where each are set to Error Action Stop, and I have a trigger set to trigger on Event Job Failed, in the default environment (triggerA). TriggerA makes use of the $job parameter when a script job fails and triggers it, then sends an alert email that a job failed and gives me the name and id of the failed job.
The issue is that it both works and does not work. When any job fails, it triggers TriggerA and I get the alert email with values for $job. However, it triggers TriggerA a second time and the email I get does not have any data listed for the values of $job. It’s somehow triggering TriggerA 2 times when any job fails, and I get 2 emails (one with $job data and another without $job data).
Any ideas on why any failed job is triggering TriggerA 2 times, and why one email has $job data where the other does not?
To take it a step further; let’s say I create another trigger (triggerB). TriggerB will clear a PSU cache variable, then send an email saying the cache was cleared. TriggerB is set to Event Job Failed, in the default environment, and I set the script to script2.
Now I’d expect any job failure to trigger triggerA, which will send 1 email alert using $job data. When script2 fails specifically, it will not only trigger triggerA but also trigger triggerB. I should receive 2 emails; one giving me the job failure alert and the other saying it cleared the cache variable, b/c script2 failed.
What’s happening is on any job failure both triggerA and triggerB are being triggered 2 times.
Any ideas on why any job failure triggers both triggers; even though one of them is set to only trigger when script2 fails?
My triggers.ps1 file
New-PSUTrigger -Name "Job Failure Alerts" -EventType "JobFailed" -Environment "Default" -TriggerScript "JobFailureAlert.ps1"
New-PSUTrigger -Name "Clear-VMwareVMs_Filtered" -Script "VMwareVMs-Filtered.ps1" -EventType "JobFailed" -Environment "Default" -TriggerScript "Clear-VMwareVMs_Filtered.ps1"