首页 > 解决方案 > Azure - 未找到与请求 URI 匹配的 HTTP 资源

问题描述

我正在使用 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

标签: azureazure-devopsazure-resource-managerarm-templateazure-resource-group

解决方案


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

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

您可以使用任务AzureResourceManagerTemplateDeployment将 设置Deployment scopeSubscription而不是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

推荐阅读