解决部署计数超出 800 的错误Resolve error when deployment count exceeds 800

每个资源组在其部署历史记录中最多只能有 800 个部署。Each resource group is limited to 800 deployments in its deployment history. 本文介绍在部署因超出允许的 800 个部署的限制而失败时可能会出现的错误。This article describes the error you receive when a deployment fails because it would exceed the allowed 800 deployments. 若要解决此错误,请从资源组历史记录中删除部署。To resolve this error, delete deployments from the resource group history. 从历史记录中删除部署不会影响已部署的任何资源。Deleting a deployment from the history doesn't affect any of the resources that were deployed.

当你接近限制时,Azure 资源管理器会自动删除历史记录中的部署。Azure Resource Manager automatically deletes deployments from your history as you near the limit. 仍出现此错误可能是由于以下原因之一:You may still see this error for one of the following reasons:

  1. 你在资源组上有一个防止从部署历史记录中删除的 CanNotDelete 锁定。You have a CanNotDelete lock on the resource group that prevents deletions from the deployment history.
  2. 你已选择退出自动删除。You've opted out of automatic deletions.
  3. 你有大量同时运行的部署,并且自动删除的处理速度不够快,无法减少总数量。You have a large number of deployments running concurrently and the automatic deletions aren't processed fast enough to reduce the total number.

有关删除锁定或选择加入自动删除的信息,请参阅从部署历史记录自动删除For information about removing the lock or opting in to automatic deletions, see Automatic deletions from deployment history.

本文介绍如何从历史记录手动删除部署。This article describes how to manually delete deployments from the history.

症状Symptom

在部署过程中,你收到错误,该错误指出当前部署会超出 800 个部署的配额。During deployment, you receive an error stating that the current deployment will exceed the quota of 800 deployments.

解决方案Solution

Azure CLIAzure CLI

使用 az deployment group delete 命令从历史记录中删除部署。Use the az deployment group delete command to delete deployments from the history.

az deployment group delete --resource-group exampleGroup --name deploymentName

若要删除五天以前的所有部署,请使用:To delete all deployments older than five days, use:

startdate=$(date +%F -d "-5days")
deployments=$(az deployment group list --resource-group exampleGroup --query "[?properties.timestamp<'$startdate'].name" --output tsv)

for deployment in $deployments
do
  az deployment group delete --resource-group exampleGroup --name $deployment
done

可使用以下命令获取部署历史记录中的当前计数:You can get the current count in the deployment history with the following command:

az deployment group list --resource-group exampleGroup --query "length(@)"

Azure PowerShellAzure PowerShell

使用 Remove-AzResourceGroupDeployment 命令从历史记录中删除部署。Use the Remove-AzResourceGroupDeployment command to delete deployments from the history.

Remove-AzResourceGroupDeployment -ResourceGroupName exampleGroup -Name deploymentName

若要删除五天以前的所有部署,请使用:To delete all deployments older than five days, use:

$deployments = Get-AzResourceGroupDeployment -ResourceGroupName exampleGroup | Where-Object Timestamp -lt ((Get-Date).AddDays(-5))

foreach ($deployment in $deployments) {
  Remove-AzResourceGroupDeployment -ResourceGroupName exampleGroup -Name $deployment.DeploymentName
}

可使用以下命令获取部署历史记录中的当前计数:You can get the current count in the deployment history with the following command:

(Get-AzResourceGroupDeployment -ResourceGroupName exampleGroup).Count

第三方解决方案Third-party solutions

以下外部解决方案解决特定场景的问题:The following external solutions address specific scenarios: