Azure使用来自VSTS Git代码的ARM模板将代码部署到服务 [英] Azure Deploy Code To Service Using ARM Template From VSTS Git Code

查看:234
本文介绍了Azure使用来自VSTS Git代码的ARM模板将代码部署到服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


  • 创建资源组。


  • 将代码从GitHub(repoUrl)部署到所述应用程序服务。



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



几乎所有东西都可以运行,直到它试图将我的C#项目从VSTS Git添加到服务中时,我会得到以下平淡的错误报告:

  New-AzureRmResourceGroupDeployment:16:08:30  - 资源Microsoft.Web / sites / sourcecontrols'webapp1nameuniques83476y4589479 / web'失败并显示消息'{
'status: 失败,
错误:{
code:ResourceDeploymentFailure,
message:终端配置状态'Failed'完成资源操作。 $(b
$ b)'在C:\Users\ [删除我的目录] \ 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 - 跳过模板输出评估:至少有一个资源部署操作失败请列出部署操作有关详细信息,请参阅https://aka.ms/arm-debug获取使用细节。在
C:\Users\ [已删除我的目录] \ 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 - 跳过模板输出评估:至少有一项资源部署操作失败。详情请列出部署操作。请参阅https://aka.ms/arm-debug获取使用详情。在
C:\Users\ [已删除我的目录] \ Deploy-AzureResources.ps1:119 char:5
+ New-AzureRmResourceGroupDeployment -Name((Get-ChildItem $ Templat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:NotSpecified:(:) [New -AzureRmResourceGroupDeployment],例外
+ 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,
参数:{
webapp1name:{
type:string,
defaultValue:webapp1nameuniques83476y4589479,
metadata:{
description:网络应用程序,你的智慧
}
},
webapp1hostingplan:{
type:string,
defaultValue:hostingplantestname,
元数据:{
description:用于托管Web应用程序的App Service计划的名称。
}
},
sku :{
type:string,
allowedValues:[
F1,
D1,
B1,
B2,
B3,
S1,
S2,
S3,
P1,
P2,
P3,
P4
],
defaultValue:S1,
metadata:{
description:托管计划的定价层。
}
},
workerSize:{
type:string,
allowedValues:[
0,
1,
2
],
defaultValue:0,
metadata:{
description :主机方案的实例大小(小型,中型或大型)。
}
},
repoURL:{
type:string ,
metadata:{
description:包含要部署的项目的GitHub存储库的URL。
}
},
分支:{
type:string,
defaultValue:master,
metadata:{
description:GitHub的分支
}
}
},
resources:[
{
apiVersion:2015-08-01 ,
name:[parameters('webapp1hostingplan')],
type:Microsoft.Web / serverfarms,
location:[resourceGroup()。位置],
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' ,参数('webapp1hostingplan'))]

properties:{
serverFarmId:[parameters('webapp1hostingplan')]
},
资源:[
{
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 repo不公开,它们是私人Git repo。



解决方法是在repo url中添加凭证。


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?

解决方案

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.

这篇关于Azure使用来自VSTS Git代码的ARM模板将代码部署到服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆