Azure - 未找到与请求 URI 匹配的 HTTP 资源

Azure - No HTTP resource was found that matches the request URI

我正在使用 YAML 管道从 Azure Devops 创建资源组。下面是我在管道中使用的 Azure 任务的片段。

- task: AzureResourceGroupDeployment@2
  displayName: 'Deploy RG'
  inputs:
    azureSubscription: 'my-servicePrinciple (SPN)'
    resourceGroupName: 'test-rg-001'
    location: 'westeurope'
    templateLocation: 'Linked artifact'
    csmFile: $(Pipeline.Workspace)/arm_templates/ResourceGroup/template.json
    csmParametersFile: $(Pipeline.Workspace)/arm_templates/ResourceGroup/parameter.json
    deploymentMode: Incremental

这是我的 template.json 文件的内容

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "rgName": {
            "type": "string"
        },
        "rgLocation": {
            "type": "string"
        },
        "tags": {
            "type": "object",
            "defaultValue": {}
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2020-06-01",
            "location": "[parameters('rgLocation')]",
            "name": "[parameters('rgName')]",
            "properties": {},
            "tags": "[parameters('tags')]"
        }
    ],
    "outputs": {}
}

管道失败并出现以下错误。

No HTTP resource was found that matches the request URI 'https://management.azure.com/subscriptions/xx4873gx-4yy1-4092-9a70-34812353vv77/resourcegroups/test-rg-001/providers/Microsoft.Resources/resourceGroups/test-rg-001?api-version=2020-06-01'

我正在网上查找是什么原因造成的,但没有希望。我还在我的 template.json 中尝试了以下架构,但它也不起作用。

"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"

奇怪的是,管道创建了我想要的资源组,但我无法理解部署失败的原因。为了获得更详细的信息,我查看了门户中的“部署”菜单,这是扩展错误

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
  "details": [
    {
      "message": "No HTTP resource was found that matches the request URI 'https://management.azure.com/subscriptions/xx4873gx-4yy1-4092-9a70-34812353vv77/resourcegroups/test-rg-001/providers/Microsoft.Resources/resourceGroups/test-rg-001?api-version=2020-06-01'."
    }
  ]
}

对于 ARM 模板,我只想创建资源组,不想包括任何其他资源的部署。 有人已经闻到了,这里做饭有什么问题吗? :D

您看到上述错误是因为您试图在管道中的资源组内创建资源组。

在您的管道中使用上述任务 AzureResourceGroupDeployment 配置。您正在资源组 test-rg-001 中创建资源组(即 test-rg-001)。如果找不到您在 resourceGroupName 参数中指定的资源组(即 test-rg-001),它将自动创建一个资源组。这就是为什么您看到资源组 test-rg-001 被奇怪地创建了。看到这个 similar issue.

您可以使用任务 AzureResourceManagerTemplateDeploymentDeployment scope 设置为 Subscription 而不是 Resource Group。见下文:

steps:
- task: AzureResourceManagerTemplateDeployment@3
  displayName: 'ARM Template deployment: Subscription scope'
  inputs:
    deploymentScope: Subscription
    azureResourceManagerConnection: 'my-servicePrinciple (SPN)'
    location: 'West Europe'
    csmFile: $(Pipeline.Workspace)/arm_templates/ResourceGroup/template.json
    csmParametersFile: $(Pipeline.Workspace)/arm_templates/ResourceGroup/parameter.json
    deploymentMode: Incremental