Sharing my experience with Azure Automation job being suspended with an exception message:
The runbook job was attempted 3 times, but it failed each time
I was working on one of the AZURE automation that involved SharePointPnPPowerShellOnline PowerShell
Every time when we check it, it was in Suspended State as Shown below:
We started troubleshooting and found that Job restarts after it is finished and does that 3 times before moving to suspend state.
The same is mentioned in exception message as well “The runbook job was attempted 3 times, but it failed each time”
Running the same script from any windows server with same modules was executing without any issues.
On doing some research on the internet we found that this is kind of bug for Azure Automation if any cmdlet is printing some output after execution, azure automation goes to error.
To resolve this, We have checked our code and added “| out-null” at the end of the cmdlet we think was causing the issue.
Add-PnPFile -Path $filePath -Folder “SiteAssets” | out-null
Voila! Problem resolved and now our jobs started completing successfully.
I hope this will help many of us that are in same situation and are scratching their head like I was.
Thanks for reading…………