Azure使用VSTS Git代码中的ARM模板部署代码服务

时间:2017-09-04 15:15:21

标签: git azure arm azure-devops continuous-deployment

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

  • 创建资源组。
  • 创建和应用服务。
  • 将代码从GitHub(repoUrl)部署到所述应用程序服务。

当我将项目放在GitHub中但是我们使用VSTS Git来保存我们的代码时,所有工作都很精彩。 我知道我可以为我创建一个VSTS作业,这是我们将要再次访问的轨道,但是我们需要能够从我们的开发人员机器运行这些ARM模板,直接从我们的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
          }
        }
      ]
    }
  ]
}

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

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:0)

这是由于在VSTS上托管的Git repo不公开,它们是私有的Git repo。

解决方法是在repo url中添加凭据。 enter image description here