【问题标题】:Azure Publish Web App with Resource Manager in PowershellAzure 在 Powershell 中使用资源管理器发布 Web 应用
【发布时间】:2018-11-08 18:37:57
【问题描述】:

我正在尝试在 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 来自旧的 Classic Manager,而 Cloud Shell 中不可用。

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

【问题讨论】:

  • 只是好奇,为什么需要使用脚本从 Cloud Shell 发布 Web App 包?
  • 我知道这看起来很奇怪,但就我而言,我无法设置持续部署流程,而且我不是负责发布 Web 应用程序的人。由于我想避免由于外部因素(例如缺少模块、缺少运行脚本的权限...)而导致的任何类型的问题,我决定创建一个可以由另一个人在我测试脚本的同一环境中执行的脚本.

标签: azure powershell azure-web-app-service azure-resource-manager azure-cloud-shell


【解决方案1】:

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

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

查看下面的链接,看看是否适合您。

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

希望这会有所帮助。

【讨论】:

  • 嗨,Hannel,可以在 cloud shell 中安装 ASM 模块吗?
  • 从我上次尝试的时候开始,它曾经是,但不再是了。但是您可以自己尝试,在 cloudshell 中运行 Install-Module Azure。用于安装模块。
  • 我也试过了,报错PackageManagement\Install-Package : The member 'TypesToProcess' in the module manifest is not valid: Cannot find path '/tmp/420647941/Azure.Storage.4.6.1/.\Microsoft.WindowsAzure.Commands.Storage.Types.ps1xml' because it does not exist.. Verify that a valid value is specified for this field in the '/tmp/420647941/Azure.Storage.4.6.1/Azure.Storage.psd1' file.所以有点迷糊。可能不支持?还没有找到一些关于它的文档。
  • 是的。它不再受支持。对不起,我试图给你完整的信息。您目前无法在 Cloudshell 上安装 ASM 模块。
【解决方案2】:

从Hannel建议的文档链接开始,我终于通过invoking REST API with Powershell解决了。使用 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

【讨论】:

    猜你喜欢
    • 2017-07-05
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2016-12-23
    • 1970-01-01
    • 2019-07-06
    • 2016-04-10
    相关资源
    最近更新 更多