Add cleanup logic for the packer os disk (#3140)

This commit is contained in:
Mikhail Timofeev
2021-04-09 14:27:14 +03:00
committed by GitHub
parent d1de678b65
commit bfd58535c2
2 changed files with 9 additions and 3 deletions

View File

@@ -92,8 +92,9 @@ jobs:
targetType: filePath
filePath: ./images.CI/linux-and-win/cleanup.ps1
arguments: -ResourcesNamePrefix $(Build.BuildId) `
-Image ${{ parameters.image_type }} `
-StorageAccount $(AZURE_STORAGE_ACCOUNT) `
-SubscriptionId $(AZURE_SUBSCRIPTION) `
-ClientId $(CLIENT_ID) `
-ClientSecret $(CLIENT_SECRET) `
-Image ${{ parameters.image_type }} `
-SubscriptionId $(AZURE_SUBSCRIPTION) `
-TenantId $(AZURE_TENANT)

View File

@@ -1,6 +1,7 @@
param(
[String] [Parameter (Mandatory=$true)] $Image,
[String] [Parameter (Mandatory=$true)] $ResourcesNamePrefix,
[String] [Parameter (Mandatory=$true)] $StorageAccount,
[String] [Parameter (Mandatory=$true)] $ClientId,
[String] [Parameter (Mandatory=$true)] $ClientSecret,
[String] [Parameter (Mandatory=$true)] $SubscriptionId,
@@ -13,9 +14,13 @@ $TempResourceGroupName = "${ResourcesNamePrefix}_${Image}"
$groupExist = az group exists --name $TempResourceGroupName --subscription $SubscriptionId
if ($groupExist -eq "true") {
$osDiskName = az group deployment list --resource-group $TempResourceGroupName --query "[].properties.parameters.osDiskName.value" -o tsv
Write-Host "Found a match, deleting temporary files"
az group delete --name $TempResourceGroupName --subscription $SubscriptionId --yes | Out-Null
Write-Host "Temporary group was deleted succesfully" -ForegroundColor Green
Write-Host "Temporary group was deleted succesfully"
Write-Host "Deleting OS disk"
az storage remove --account-name $StorageAccount -c "images" -n "$osDiskName.vhd" | Out-Null
Write-Host "OS disk deleted"
} else {
Write-Host "No temporary groups found"
}