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
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)" `