通过 Powershell 或 CLI 配置 Azure Web 应用程序部署槽
Configure Azure web app deployment slot via Powershell or CLI
我正在为我们的一个 Azure Web 应用程序设置一个 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
所有这些工作正常,直到最后一个命令,returns 这个错误:
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 部署手动配置的另一个部署槽使用的格式相匹配。在我看来这应该可行,但显然我遗漏了一些重要的细节。
事实证明,如果您从本地 git 部署,则 repoUrl 是 派生的 属性。要启用本地 git 部署,您可以在不同的位置设置不同的 属性。
Microsoft 支持向我指出了 a different guide 的方向,我可以按照该方向配置部署槽。
最后几行的修改版本如下所示:
$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 Power Shell 和 Azure CLi 来执行此操作。
功率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 客户端 2.0
az webapp deployment source config-local-git --name --resource-group --slot
看到这个link
希望对您有所帮助。
我正在为我们的一个 Azure Web 应用程序设置一个 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
所有这些工作正常,直到最后一个命令,returns 这个错误:
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 部署手动配置的另一个部署槽使用的格式相匹配。在我看来这应该可行,但显然我遗漏了一些重要的细节。
事实证明,如果您从本地 git 部署,则 repoUrl 是 派生的 属性。要启用本地 git 部署,您可以在不同的位置设置不同的 属性。
Microsoft 支持向我指出了 a different guide 的方向,我可以按照该方向配置部署槽。
最后几行的修改版本如下所示:
$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 Power Shell 和 Azure CLi 来执行此操作。
功率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 客户端 2.0
az webapp deployment source config-local-git --name --resource-group --slot
看到这个link
希望对您有所帮助。