Azure 使用来自 VSTS Git 代码的 ARM 模板将代码部署到服务

Azure Deploy Code To Service Using ARM Template From VSTS Git Code

我创建了一个 ARM 模板并将其用于:

当我将我的项目放在 GitHub 中时,一切都很好,但我们正在使用 VSTS Git 来保存我们的代码。 我知道我可以创建一个 VSTS 作业来为我做这件事,这是我们将再次进入的轨道,但是我们需要能够 运行 从我们的开发人员机器上使用这些 ARM 模板,运行ning直接来自我们的 Visual Studios 或 Powershell ISE。

几乎一切正常,直到它尝试将我的 C# 项目从 VSTS Git 添加到服务中,我收到以下平淡的错误报告:

New-AzureRmResourceGroupDeployment : 16:08:30 - Resource Microsoft.Web/sites/sourcecontrols 'webapp1nameuniques83476y4589479/web' failed with message '{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'."
  }
}'At C:\Users\[removed my directory]\Deploy-AzureResources.ps1:119 char:5
+     New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $Templat ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : 16:08:30 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.At 
C:\Users\[removed my directory]\Deploy-AzureResources.ps1:119 char:5
+     New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $Templat ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : 16:08:30 - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.At 
C:\Users\[removed my directory]\Deploy-AzureResources.ps1:119 char:5
+     New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $Templat ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

我使用的模板是:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "webapp1name": {
      "type": "string",
      "defaultValue": "webapp1nameuniques83476y4589479",
      "metadata": {
        "description": "The name of the web app that you wish to create."
      }
    },
    "webapp1hostingplan": {
      "type": "string",
      "defaultValue": "hostingplantestname",
      "metadata": {
        "description": "The name of the App Service plan to use for hosting the web app."
      }
    },
    "sku": {
      "type": "string",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "defaultValue": "S1",
      "metadata": {
        "description": "The pricing tier for the hosting plan."
      }
    },
    "workerSize": {
      "type": "string",
      "allowedValues": [
        "0",
        "1",
        "2"
      ],
      "defaultValue": "0",
      "metadata": {
        "description": "The instance size of the hosting plan (small, medium, or large)."
      }
    },
    "repoURL": {
      "type": "string",
      "metadata": {
        "description": "The URL for the GitHub repository that contains the project to deploy."
      }
    },
    "branch": {
      "type": "string",
      "defaultValue": "master",
      "metadata": {
        "description": "The branch of the GitHub repository to use."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('webapp1hostingplan')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "[parameters('sku')]",
        "capacity": "[parameters('workerSize')]"
      },
      "properties": {
        "name": "[parameters('webapp1hostingplan')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('webapp1name')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('webapp1hostingplan'))]"
      ],
      "properties": {
        "serverFarmId": "[parameters('webapp1hostingplan')]"
      },
      "resources": [
        {
          "apiVersion": "2015-08-01",
          "name": "web",
          "type": "sourcecontrols",
          "dependsOn": [
            "[resourceId('Microsoft.Web/Sites', parameters('webapp1name'))]"
          ],
          "properties": {
            "RepoUrl": "[parameters('repoURL')]",
            "branch": "[parameters('branch')]",
            "IsManualIntegration": true
          }
        }
      ]
    }
  ]
}

它以创建所有资源结束,但应用程序服务没有部署任何代码项目。

知道我做错了什么吗?

这是因为托管在 VSTS 上的 Git 存储库不是 public,它们是私人 Git 存储库。

解决方法是在存储库 url 中添加凭据。