1

我正在尝试在 Azure 上的应用服务上发布 Web 应用程序包。为了发布包,我需要创建一个 Powershell 脚本以从 Cloud Shell 运行。我写了以下代码

Import-AzurePublishSettingsFile - $WebApp.PublishProfilePath
Publish-AzureWebsiteProject -Package $WebApp.ZipPath -Name $WebApp.WebAppName

此代码适用于我的本地计算机,但不适用于出现以下错误的 Cloud Shell:

Import-AzurePublishSettingsFile : The term 'Import-AzurePublishSettingsFile' 
is not recognized as the name of a cmdlet, function, script file, or 
operable program.

Publish-AzureWebsiteProject : The term 'Publish-AzureWebsiteProject' is not 
recognized as the name of a cmdlet, function, script file, or operable 
program.

我猜这些错误是由于这些 cmdlet 来自旧的经典管理器,而后者在 Cloud Shell 中不可用。

基本上我需要使用脚本从 Cloud Shell发布一个 Web App 包。我怎样才能做到这一点?我还有其他选择吗?

4

2 回答 2

2

从 Hannel 建议的文档链接开始,我最终通过使用 Powershell 调用 REST API来解决。使用 Azure CLI 要容易得多,但我已经用 Powershell 编写了一个更复杂的脚本。

最终代码是这样的:

# Getting credentials
$creds = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName `
    -ResourceType Microsoft.Web/sites/config `
    -ResourceName "$($WebApp.WebAppName)/publishingcredentials" `
    -Action list `
    -ApiVersion 2015-08-01 `
    -Force

$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))

# Deploy Web App
Invoke-RestMethod -Uri "https://$($WebApp.WebAppName).scm.azurewebsites.net/api/zipdeploy" `
    -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo)} `
    -Method POST `
    -InFile $WebApp.ZipPath `
    -ContentType "multipart/form-data"  `
    -UseBasicParsing `
    -ErrorAction Stop | Out-Null
于 2018-11-09T08:46:00.403 回答
2

您遵循的步骤和命令适用于 ASM(经典)网站部署。

Shell 是否只能具有 ARM 模块,而没有具有这些命令的模块。

检查下面的链接,看看它是否适合你。

https://docs.microsoft.com/en-us/azure/app-service/app-service-deploy-zip

希望这可以帮助。

于 2018-11-09T06:00:45.287 回答