部署管道中的 AzPowerShell 脚本任务。删除和创建 Az 存储时解决冲突错误的方法有哪些 Table
AzPowerShell Script Task in Deployment Pipeline. What are some of the ways to resolve a Conflict error when Removing and Create an Az Storage Table
我有一个带有 Azure PowerShell 脚本任务的 Azure DevOps 部署管道。
脚本任务填充 Azure 存储 Table。它从 json 文件中获取数据。
不幸的是,我的客户在 table.
中不断改变他们想要的东西
所以,我认为最好的办法是删除 table,重新创建它并用新数据重新填充它。
但是,如果我 运行 背对背删除和创建,我会收到冲突错误。这是有道理的,因为 Azure 似乎有很多使用消息传递架构。
无论如何,有人有解决这个问题的方法吗?我有一些,但它们似乎是偷工减料的。
这里是代码的一个子集:
$storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$storageTable = Get-AzStorageTable `
-Name $tableName `
-Context $storageAccount.Context `
-ErrorVariable ev `
-ErrorAction SilentlyContinue
if($storageTable) {
Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context -Force
}
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
$storageTable = Get-AzStorageTable -Name $tableName -Context $storageAccount.Context
如有任何建议,我们将不胜感激。
我对您的代码做了一些修改。请按照以下代码段
$storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$storageTable = Get-AzStorageTable `
-Name $tableName `
-Context $storageAccount.Context `
-ErrorVariable ev `
-ErrorAction SilentlyContinue
# if you dont have the table it will gives the $ev so you have to capture this and if table is not there we have to create
if ($ev) {
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
$isDeleted = $false
write-host("Table is not there it is created")
}
# if table exist you can remove the table
elseif($storageTable.Name -eq $tableName) {
Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context
$isDeleted = $true
write-host("Table is there so it is Removed")
# After deleting table we have to wait for 40 sec to completely delete the table from Garbage. Mean while we cannot access the table storage.
Start-Sleep -Seconds 40
}
if($isDeleted -eq $true)
{
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
write-host("Table is Removed so it is created")
}
$storageTable = Get-AzStorageTable -Name $tableName -Context $storageAccount.Context
After Deleting/Removing a table it is immediately marked for deletion and is no longer accessible to clients is likely to take at least 40 seconds
to complete on that time it will be in a Garbage collection. Refer here
结果:
我有一个带有 Azure PowerShell 脚本任务的 Azure DevOps 部署管道。
脚本任务填充 Azure 存储 Table。它从 json 文件中获取数据。
不幸的是,我的客户在 table.
中不断改变他们想要的东西所以,我认为最好的办法是删除 table,重新创建它并用新数据重新填充它。
但是,如果我 运行 背对背删除和创建,我会收到冲突错误。这是有道理的,因为 Azure 似乎有很多使用消息传递架构。
无论如何,有人有解决这个问题的方法吗?我有一些,但它们似乎是偷工减料的。
这里是代码的一个子集:
$storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$storageTable = Get-AzStorageTable `
-Name $tableName `
-Context $storageAccount.Context `
-ErrorVariable ev `
-ErrorAction SilentlyContinue
if($storageTable) {
Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context -Force
}
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
$storageTable = Get-AzStorageTable -Name $tableName -Context $storageAccount.Context
如有任何建议,我们将不胜感激。
我对您的代码做了一些修改。请按照以下代码段
$storageAccount = Get-AzStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$storageTable = Get-AzStorageTable `
-Name $tableName `
-Context $storageAccount.Context `
-ErrorVariable ev `
-ErrorAction SilentlyContinue
# if you dont have the table it will gives the $ev so you have to capture this and if table is not there we have to create
if ($ev) {
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
$isDeleted = $false
write-host("Table is not there it is created")
}
# if table exist you can remove the table
elseif($storageTable.Name -eq $tableName) {
Remove-AzStorageTable -Name $tableName -Context $storageAccount.Context
$isDeleted = $true
write-host("Table is there so it is Removed")
# After deleting table we have to wait for 40 sec to completely delete the table from Garbage. Mean while we cannot access the table storage.
Start-Sleep -Seconds 40
}
if($isDeleted -eq $true)
{
New-AzStorageTable -Name $tableName -Context $storageAccount.Context
write-host("Table is Removed so it is created")
}
$storageTable = Get-AzStorageTable -Name $tableName -Context $storageAccount.Context
After Deleting/Removing a table it is immediately marked for deletion and is no longer accessible to clients is likely to take at least
40 seconds
to complete on that time it will be in a Garbage collection. Refer here