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

不打扰是莪最后的温柔 提交于 2020-01-03 05:58:11

问题


I have created an ARM template and am using it to:

  • Create a resource group.
  • Create and Application Service.
  • Deploy code from GitHub (repoUrl) to said Application Service.

All works wonderfully when I place my project inside GitHub but we are using VSTS Git to hold our code. I know I can create a VSTS jobs that will do this for me and this is the track we will get to again however we need to be able to run these ARM templates from our developer machines, running direct from our Visual Studios or Powershell ISE's.

Almost everything works until it tries to add my C# project from VSTS Git to the service I get the following bland error report:

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

The template I am using is:

{
  "$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
          }
        }
      ]
    }
  ]
}

It ends with all resources created but the application service has no code project deployed to it.

any ideas what I am doing wrong?


回答1:


This is due to Git repo hosted on VSTS is not public, they are private Git repo.

The workaround around is adding the credentials in the repo url.



来源:https://stackoverflow.com/questions/46039975/azure-deploy-code-to-service-using-arm-template-from-vsts-git-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!