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

标签 powershell azure deployment azure-web-app-service azure-powershell

我正在为我们的一个 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

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

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 部署手动配置的另一个部署槽使用的格式相匹配。在我看来这应该可行,但显然我遗漏了一些重要的细节。

最佳答案

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

电源外壳。

# 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

希望这有帮助。

关于powershell - 通过 Powershell 或 CLI 配置 Azure Web 应用程序部署槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48625525/

相关文章:

azure - 使用 powershell 将 Azure 订阅移至另一个租户

powershell - 将命令行编辑保存到相同(源)文本文件

powershell - Powershell输出txt文件中的记录列表

ruby-on-rails-3 - Heroku 重启 = 找不到资源?

testing - 回归测试和部署策略

外部命令静默失败的 Powershell 错误

azure - 如何使用 Azure B2C 保护 Azure API 管理 API

azure - 如果我们在Azure DevOps Services中创建项目时选择TFVC版本控制,是否可以进行代码审查?

azure - 选择 Azure 中 VM 的数量和大小

java - Jboss AS 7 未部署从 rt.jar(1.6.0_20) 提供 Servlet 异常