使用 TFS15 自动发布云服务到 Azure
Automatically publishing cloud service to Azure using TFS15
过去几天我一直在研究构建系统,该系统可以持续将网站部署到 Azure 上的暂存系统。我相信我已经非常接近让它正常工作了,但是当 Azure 尝试使用 MSDeploy 扩展配置网站时我收到错误消息。
我的过程概述:
使用 Team Foundation Server 2015(自托管,而非 VSO),我创建了一个具有 "Visual Studio Build" 步骤的构建定义:
这将使用以下参数运行 MSBuild:
/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
这会创建一个名为 WebRole1.zip 的 ZIP 文件,可以在 $(Build.ArtifactStagingDirectory)\AzureTestBuilds\WebRole1.zip
中找到
接下来,构建使用 Powershell 脚本连接到 Azure,将上述 ZIP 文件上传到存储 blob,并使用基于 JSON 的模板配置站点。该模板具有以下用于部署站点的 MSDeploy 扩展:
"resources": [
{
"apiVersion": "2014-06-01",
"type": "Extensions",
"name": "MSDeploy",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('WebAPIURL'))]"
],
"properties": {
"packageUri": "[concat(variables('SiteStagingStorageURL'), '/zips/WebRole1.zip', parameters('sasToken'))]",
"dbType": "None",
"connectionString": "",
"setParameters": {
"Application Path": "[variables('WebAPIURL')]"
}
}
}
]
构建运行时,出现以下错误:
4:21:31 PM - Resource Microsoft.Web/sites/Extensions
'xxx-WebAPI/MSDeploy' failed with message 'The resource operation
completed with terminal provisioning state 'Failed'.'
在 Kudu(Azure 诊断控制台)中,我看到一个更详细的错误:
<?xml version="1.0" encoding="utf-8"?>
<entries>
<entry time="2016-02-13T00:21:51.3365955+00:00" type="Message">
<message>Downloading metadata for package path 'zips/WebRole1.zip' from blob 'https://xxx.blob.core.windows.net'</message>
</entry>
<entry time="2016-02-13T00:21:51.8023866+00:00" type="Message">
<message>The blob has flag IsPremiumApp:. IsPremiumApp returns False</message>
</entry>
<entry time="2016-02-13T00:21:51.8805277Z" type="Message">
<message>Downloading package path 'zips/WebRole1.zip' from blob 'https://xxx.blob.core.windows.net'</message>
</entry>
<entry time="2016-02-13T00:21:52.2711541Z" type="Error">
<message>AppGallery Deploy Failed: 'Microsoft.Web.Deployment.DeploymentXmlException: The declared parameter 'Application Path' is not recognized.
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.LoadFromFile(XPathNavigator nav, String fileName, Boolean ignoreExtraSetParameters)
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.LoadXml(String xml)
at Microsoft.Web.Deployment.WebApi.AppGalleryPackage.LoadSetParameters(DeploymentObject deploymentObject, IDictionary`2 setParams)
at Microsoft.Web.Deployment.WebApi.AppGalleryPackage.Deploy(String deploymentSite, String siteSlotId)
at Microsoft.Web.Deployment.WebApi.DeploymentController.<DownloadAndDeployPackage>d__b.MoveNext()'</message>
</entry>
</entries>
据我所知,zip 的 XML 清单中的参数不正确。我花了很多时间阅读有关如何使用 MSDeploy 构建扩展在 Azure 上部署站点的各种博客和教程,但它们都使用现有的 sample ZIP 文件。我找不到有关这些 zip 文件和 XML 清单的正确格式的任何信息,也找不到如何使用 MSBuild 创建有效文件的信息。我在这里缺少一个步骤吗?如果需要更多信息,我很乐意 post。
JSON 值可以是:
A number (integer or floating point)
A string (in double quotes)
A Boolean (true or false)
An array (in square brackets)
An object (in curly braces)
null
但您似乎在值字段中使用了函数(变量('WebAPIURL'))。恐怕是问题所在。
想通了。我不得不将一个名为 parameters.xml
的文件添加到项目的根文件夹(与 web.config
和 Global.asax
相同的文件夹。该文件包含以下内容:
<parameters>
<parameter name="Application Path" description="Full site path where you would like to install your application (i.e., Default Web Site/WebRole1)" defaultValue="Default Web Site/WebRole1" tags="iisapp">
<parameterEntry type="ProviderPath" scope="iisapp" match="WebRole1" />
</parameter>
<parameter name="SetAclParameter1" description="Hidden - automatically sets write access for the app" defaultValue="{Application Path}/App_Data" tags="Hidden, NoDatabase">
<parameterEntry type="ProviderPath" scope="setAcl" match="WebRole1/App_Data" />
</parameter>
</parameters>
将 WebRole1
更改为您的 Web 项目的任何名称。 MSDeploy 似乎只是自动获取此文件,无需更改任何其他设置或构建参数。
过去几天我一直在研究构建系统,该系统可以持续将网站部署到 Azure 上的暂存系统。我相信我已经非常接近让它正常工作了,但是当 Azure 尝试使用 MSDeploy 扩展配置网站时我收到错误消息。
我的过程概述:
使用 Team Foundation Server 2015(自托管,而非 VSO),我创建了一个具有 "Visual Studio Build" 步骤的构建定义:
这将使用以下参数运行 MSBuild:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
这会创建一个名为 WebRole1.zip 的 ZIP 文件,可以在 $(Build.ArtifactStagingDirectory)\AzureTestBuilds\WebRole1.zip
接下来,构建使用 Powershell 脚本连接到 Azure,将上述 ZIP 文件上传到存储 blob,并使用基于 JSON 的模板配置站点。该模板具有以下用于部署站点的 MSDeploy 扩展:
"resources": [
{
"apiVersion": "2014-06-01",
"type": "Extensions",
"name": "MSDeploy",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('WebAPIURL'))]"
],
"properties": {
"packageUri": "[concat(variables('SiteStagingStorageURL'), '/zips/WebRole1.zip', parameters('sasToken'))]",
"dbType": "None",
"connectionString": "",
"setParameters": {
"Application Path": "[variables('WebAPIURL')]"
}
}
}
]
构建运行时,出现以下错误:
4:21:31 PM - Resource Microsoft.Web/sites/Extensions 'xxx-WebAPI/MSDeploy' failed with message 'The resource operation completed with terminal provisioning state 'Failed'.'
在 Kudu(Azure 诊断控制台)中,我看到一个更详细的错误:
<?xml version="1.0" encoding="utf-8"?>
<entries>
<entry time="2016-02-13T00:21:51.3365955+00:00" type="Message">
<message>Downloading metadata for package path 'zips/WebRole1.zip' from blob 'https://xxx.blob.core.windows.net'</message>
</entry>
<entry time="2016-02-13T00:21:51.8023866+00:00" type="Message">
<message>The blob has flag IsPremiumApp:. IsPremiumApp returns False</message>
</entry>
<entry time="2016-02-13T00:21:51.8805277Z" type="Message">
<message>Downloading package path 'zips/WebRole1.zip' from blob 'https://xxx.blob.core.windows.net'</message>
</entry>
<entry time="2016-02-13T00:21:52.2711541Z" type="Error">
<message>AppGallery Deploy Failed: 'Microsoft.Web.Deployment.DeploymentXmlException: The declared parameter 'Application Path' is not recognized.
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.LoadFromFile(XPathNavigator nav, String fileName, Boolean ignoreExtraSetParameters)
at Microsoft.Web.Deployment.DeploymentSyncParameterCollection.LoadXml(String xml)
at Microsoft.Web.Deployment.WebApi.AppGalleryPackage.LoadSetParameters(DeploymentObject deploymentObject, IDictionary`2 setParams)
at Microsoft.Web.Deployment.WebApi.AppGalleryPackage.Deploy(String deploymentSite, String siteSlotId)
at Microsoft.Web.Deployment.WebApi.DeploymentController.<DownloadAndDeployPackage>d__b.MoveNext()'</message>
</entry>
</entries>
据我所知,zip 的 XML 清单中的参数不正确。我花了很多时间阅读有关如何使用 MSDeploy 构建扩展在 Azure 上部署站点的各种博客和教程,但它们都使用现有的 sample ZIP 文件。我找不到有关这些 zip 文件和 XML 清单的正确格式的任何信息,也找不到如何使用 MSBuild 创建有效文件的信息。我在这里缺少一个步骤吗?如果需要更多信息,我很乐意 post。
JSON 值可以是:
A number (integer or floating point)
A string (in double quotes)
A Boolean (true or false)
An array (in square brackets)
An object (in curly braces)
null
但您似乎在值字段中使用了函数(变量('WebAPIURL'))。恐怕是问题所在。
想通了。我不得不将一个名为 parameters.xml
的文件添加到项目的根文件夹(与 web.config
和 Global.asax
相同的文件夹。该文件包含以下内容:
<parameters>
<parameter name="Application Path" description="Full site path where you would like to install your application (i.e., Default Web Site/WebRole1)" defaultValue="Default Web Site/WebRole1" tags="iisapp">
<parameterEntry type="ProviderPath" scope="iisapp" match="WebRole1" />
</parameter>
<parameter name="SetAclParameter1" description="Hidden - automatically sets write access for the app" defaultValue="{Application Path}/App_Data" tags="Hidden, NoDatabase">
<parameterEntry type="ProviderPath" scope="setAcl" match="WebRole1/App_Data" />
</parameter>
</parameters>
将 WebRole1
更改为您的 Web 项目的任何名称。 MSDeploy 似乎只是自动获取此文件,无需更改任何其他设置或构建参数。