尋找錯誤碼

當使用 Azure Resource Manager 範本 (ARM 範本) 或 Bicep 檔案進行的 Azure 資源部署失敗時,會收到錯誤碼。 本文說明如何尋找錯誤碼,讓您可以針對問題進行疑難排解。 如需錯誤碼的詳細資訊,請參閱常見的部署錯誤

錯誤類型

有三種與部署相關的錯誤類型:

  • 驗證錯誤發生於部署開始之前,並且為檔案中的語法錯誤所造成。 Visual Studio Code 之類的程式碼編輯器可識別這些錯誤。
  • 預檢驗證錯誤發生於執行部署命令但未部署資源時。 在不啟動部署的情況下找到這些錯誤。 例如,若參數值不正確,則會在預檢驗證中找到錯誤。
  • 部署錯誤發生在部署過程中,且只能藉由評估 Azure 環境中的部署進度將其找出。

所有錯誤類型都會傳回錯誤碼,以供您針對部署進行疑難排解之用。 驗證與預檢錯誤會顯示在活動記錄中,但不會出現在部署歷程記錄中。 含有語法錯誤的 Bicep 檔案不會編譯成 JSON,也不會顯示在活動記錄中。

若要辨別語法錯誤,您可以使用 Visual Studio Code 搭配最新的 Bicep 延伸模組Azure Resource Manager 工具延伸模組

驗證錯誤

範本會在部署程序期間進行驗證,並顯示錯誤碼。 執行部署之前,您可以使用 Azure PowerShell 或 Azure CLI 執行驗證測試,以識別驗證和預檢錯誤。

您可以從入口網站部署 ARM 範本。 如果範本有語法錯誤,當您嘗試執行部署時,您會看到驗證錯誤。 如需入口網站部署的詳細資訊,請參閱從自訂範本部署資源

下列範例是在嘗試部署儲存體帳戶時發生驗證錯誤。

Screenshot of a validation error in the Azure portal for a storage account deployment attempt.

選取訊息以取得詳細資訊。 範本有語法錯誤,錯誤碼為 InvalidTemplate。 [摘要] 顯示運算式遺漏右括弧。

Screenshot of a validation error message in the Azure portal, showing a syntax error with error code InvalidTemplate.

部署錯誤

系統會處理數個作業,以部署 Azure 資源。 當作業通過驗證但是在部署期間失敗時,您會收到部署錯誤。 您可以檢視每個部署作業以及資源群組中每個部署的相關訊息。

若要查看部署作業的相關訊息,請使用資源群組的活動記錄

  1. 登入 Azure 入口網站

  2. 前往 [資源群組],然後選取部署的資源群組名稱。

  3. 選取 [活動記錄]

  4. 使用篩選器來尋找作業的錯誤記錄檔。

    Screenshot of the Azure portal's resource group activity log, emphasizing a failed deployment with an error log.

  5. 選取錯誤記錄檔,以查看作業的詳細資料。

    Screenshot of the activity log details in the Azure portal, showing a failed deployment's error message and operation details.

若要檢視部署的結果:

  1. 移至資源群組。

  2. 選取 [設定]>[部署]

  3. 選取部署的 [錯誤詳細資料]

    Screenshot of a resource group's deployments section in the Azure portal, displaying a link to error details for a failed deployment.

  4. 系統會顯示錯誤訊息和錯誤碼 NoRegisteredProviderFound

    Screenshot of a deployment error summary in the Azure portal, showing the error message and error code NoRegisteredProviderFound.

下一步