通过Powershell或CLI配置Azure Web应用程序部署插槽

时间:2018-02-05 15:08:37

标签: powershell azure deployment azure-web-sites azure-powershell

我正在为我们的一个Azure网络应用程序设置CI脚本,我想使用部署插槽将应用程序的每个分支部署支持到我们的开发订阅中。

我可以轻松创建部署插槽,并且通过PowerShell配置应用设置已经取得了一些成功。

目前的主要问题是我还需要为新创建的插槽配置部署选项。我们通过本地git存储库发布我们的网站。我尝试过同时使用PowerShell和CLI,但是我在设置repoUrl参数时遇到错误。

我在example from Microsoft之后建立了这个脚本。此外,我验证了命令语法与Azure资源管理器中显示的内容相匹配。

$ResourceGroupName = "group-name"
$SubscriptionId = "guid-value-redacted"

Login-AzAccount -Subscription $SubscriptionId

# Configure environment properties

$WebAppName = "web-app-name"
$AppServicePlanName = "web-app-plan-name"
$SlotName = "branch-name"

New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -AppServicePlan $AppServicePlanName -Name $WebAppName -Slot $SlotName

$PropertiesObject = @{
    repoUrl = "https://$WebAppName-$SlotName.scm.azurewebsites.net/"
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/sourcecontrols -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force

所有这些工作正常,直到最后一个命令,它返回此错误:

Set-AzureRmResource : {"Code":"BadRequest","Message":"The parameter https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid value.","Target":null,"Details":[{"Message":"The parameter 
https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid value."},{"Code":"BadRequest"},{"ErrorEntity":{"ExtendedCode":"51008","MessageTemplate":"The parameter {0} has an invalid 
value.","Parameters":["https://web-app-name-branch-name.scm.azurewebsites.net/"],"Code":"BadRequest","Message":"The parameter https://web-app-name-branch-name.scm.azurewebsites.net/ has an invalid 
value."}}],"Innererror":null}
At line:6 char:1
+ Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : BadRequest,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResourceCmdlet

我在这里做错了什么?我知道该示例基于从GitHub发布,但我在这里提供的参数与我为本地git部署手动配置的另一个部署插槽使用的格式相匹配。在我看来,这应该是有用的,但显然我错过了一些重要的细节。

2 个答案:

答案 0 :(得分:3)

您可以使用Azure Power Shell和Azure CLi执行此操作。

Power Shell。

# Configure environment properties
$ResourceGroupName = "shuiapp"
$WebAppName = "shuicli"
$AppServicePlanName = "myAppServicePlan"
$SlotName = "shuislot"

New-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -AppServicePlan $AppServicePlanName -Name $WebAppName -Slot $SlotName

$PropertiesObject = @{
    scmType = "LocalGit";
}

Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force

Azure Cli 2.0

az webapp deployment source config-local-git --name --resource-group --slot

请参阅此link

希望这有帮助。

答案 1 :(得分:1)

如果从本地git部署,事实证明repoUrl是派生的属性。要启用本地git部署,请在其他位置设置其他属性。

Microsoft支持向我指出了SparseMatrix的方向,我可以按照它来配置部署插槽。

最后几行的修改版本如下所示:

$PropertiesObject = @{
    scmType = "LocalGit";
}
Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/slots/config -ResourceName "$WebAppName/$SlotName/web" -ApiVersion 2016-08-01 -Force
相关问题