I'm building a packer pipeline and having an issue in getting the failure of a powershell provisioner step to fail the packer job itself. This is important as without failing the Packer job, the AMI would be published, despite the test failure.
How I'm proceeding:
Invoke-Pester
However, even with issue count being > 0 it is not causing the pipeline to fail. Additionally some errors thrown in other provisioner steps also fail to cause the Packer job to stop. I've set $ErrorActionPreference = 'Stop'
on one of them and it didn't seem to make any difference.
Here's part of the provisioning workflow for packer.
ERROR Rendering Code Block
Once this part is done it's followed by this step which is some logic from this blog post:
ERROR Rendering Code Block
The Get-TestResults.ps1
has the following function thanks to this article: Testing Packer Images with Pester written originally by Sam Cogan and modified slightly by me.
ERROR Rendering Code Block
I found one syntax issue when reworking through this, as the default Packer behavior per PowerShell's default behavior is $ErrorActionPreference = 'continue'
. I set manually now at the top of all my scripts and also fixed a syntax issue on Get-TestResults
and will see if it works correctly this time. Fingers crossed