From 520f852a2148f06a8538309bc57b76b4f5b96431 Mon Sep 17 00:00:00 2001 From: jeffpuckett Date: Mon, 30 May 2022 08:40:06 -0400 Subject: [PATCH] Add option to auto clean up packer resources if there is an error during packer image creation (#5635) * Add option to auto clean up packer resources if there is an error during packer image creation * Add option to auto clean up packer resources if there is an error during packer image creation * Add option to auto clean up packer resources if there is an error during packer image creation Co-authored-by: Jeff Puckett --- helpers/GenerateResourcesAndImage.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helpers/GenerateResourcesAndImage.ps1 b/helpers/GenerateResourcesAndImage.ps1 index d90dc87c..27659c9c 100644 --- a/helpers/GenerateResourcesAndImage.ps1 +++ b/helpers/GenerateResourcesAndImage.ps1 @@ -88,6 +88,8 @@ Function GenerateResourcesAndImage { .PARAMETER AllowBlobPublicAccess The Azure storage account will be created with this option. + .PARAMETER OnError + Specify how packer handles an error during image creation. .EXAMPLE GenerateResourcesAndImage -SubscriptionId {YourSubscriptionId} -ResourceGroupName "shsamytest1" -ImageGenerationRepositoryRoot "C:\virtual-environments" -ImageType Ubuntu1804 -AzureLocation "East US" #> @@ -119,6 +121,9 @@ Function GenerateResourcesAndImage { [Parameter(Mandatory = $False)] [bool] $EnableHttpsTrafficOnly = $False, [Parameter(Mandatory = $False)] + [ValidateSet("abort","ask","cleanup","run-cleanup-provisioner")] + [string] $OnError = "ask", + [Parameter(Mandatory = $False)] [hashtable] $Tags ) @@ -281,7 +286,7 @@ Function GenerateResourcesAndImage { $builderScriptPath = $builderScriptPath_temp } - & $packerBinary build -on-error=ask ` + & $packerBinary build -on-error=$($OnError) ` -var "client_id=$($spClientId)" ` -var "client_secret=$($ServicePrincipalClientSecret)" ` -var "subscription_id=$($SubscriptionId)" `