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 <jpuckett@yprime.com>
This commit is contained in:
jeffpuckett
2022-05-30 08:40:06 -04:00
committed by GitHub
parent a814bcd513
commit 520f852a21

View File

@@ -88,6 +88,8 @@ Function GenerateResourcesAndImage {
.PARAMETER AllowBlobPublicAccess .PARAMETER AllowBlobPublicAccess
The Azure storage account will be created with this option. The Azure storage account will be created with this option.
.PARAMETER OnError
Specify how packer handles an error during image creation.
.EXAMPLE .EXAMPLE
GenerateResourcesAndImage -SubscriptionId {YourSubscriptionId} -ResourceGroupName "shsamytest1" -ImageGenerationRepositoryRoot "C:\virtual-environments" -ImageType Ubuntu1804 -AzureLocation "East US" GenerateResourcesAndImage -SubscriptionId {YourSubscriptionId} -ResourceGroupName "shsamytest1" -ImageGenerationRepositoryRoot "C:\virtual-environments" -ImageType Ubuntu1804 -AzureLocation "East US"
#> #>
@@ -119,6 +121,9 @@ Function GenerateResourcesAndImage {
[Parameter(Mandatory = $False)] [Parameter(Mandatory = $False)]
[bool] $EnableHttpsTrafficOnly = $False, [bool] $EnableHttpsTrafficOnly = $False,
[Parameter(Mandatory = $False)] [Parameter(Mandatory = $False)]
[ValidateSet("abort","ask","cleanup","run-cleanup-provisioner")]
[string] $OnError = "ask",
[Parameter(Mandatory = $False)]
[hashtable] $Tags [hashtable] $Tags
) )
@@ -281,7 +286,7 @@ Function GenerateResourcesAndImage {
$builderScriptPath = $builderScriptPath_temp $builderScriptPath = $builderScriptPath_temp
} }
& $packerBinary build -on-error=ask ` & $packerBinary build -on-error=$($OnError) `
-var "client_id=$($spClientId)" ` -var "client_id=$($spClientId)" `
-var "client_secret=$($ServicePrincipalClientSecret)" ` -var "client_secret=$($ServicePrincipalClientSecret)" `
-var "subscription_id=$($SubscriptionId)" ` -var "subscription_id=$($SubscriptionId)" `