Hello.
I'm struggling to properly send a notification in case something bad happens in a configuration job. Example of a simple configuration plan that simulates this:
##AH:UseTextMode
try
{
Ensure-File C:\Temp\ensure.txt
(
Text: This is just a simple ensure action.
);
Start-Service missing_service
(
FailIfServiceDoesNotExist: true
);
}
catch
{
Post-Http $webookUrl
(
ContentType: application/json, TextData: '{"text": "Failure"}'
);
}
Message is never send. I assume it is because a configuration drift occurred in a "try" block so no other blocks are executed. I am able to resolve this issue by placing the post action inside a block with an execution policy set to always:
##AH:UseTextMode
try
{
Ensure-File C:\Temp\ensure.txt
(
Text: This is just a simple ensure action.
);
Start-Service missing_service
(
FailIfServiceDoesNotExist: true
);
}
catch
{
# CachAlwaysBlock
with executionPolicy=always
{
Post-Http $webookUrl
(
ContentType: application/json, TextData: '{"text": "Message B"}'
);
}
}
It works. But the problem now is that when I switch plan to a visual editor and than back to the text mode again the whole "with" statement disappear. So it's very dangerous to use it.
Maybe I got it all wrong and there is a better way how to automatically inform my team that something bad had happened. But if such a mechanism exists in Otter, I'm no aware of it.
Is "with executionPolicy=always" a bad idea to use and there is a better way of handling failures, or is it the only way?