如何使用PowerShell(az模块)部署到Azure App Service?

时间:2019-08-27 06:09:18

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

我想从Powershell部署应用程序服务。 我只想使用发布个人资料(天蓝色帐户没有密码)。

我尝试了FTP服务,但有时文件被运行的用户阻止。 我想我必须停止应用服务。

有powershell命令,例如:

Publish-AzWebApp

但是首先我需要登录:

Connect-AzAccount

并传递我要避免的凭据。

有什么方法可以仅基于发布的个人资料来调用Publish-AzWebApp(不能通过帐户登录)?

Connect-AzAccount还有其他登录选项(令牌或证书)。 不幸的是,我不知道如何生成它。

顺便说一句,有一个关于它的话题: How do I deploy to Azure App Service with PowerShell? 但是它很旧,现在建议使用模块“ az”。

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

  

有什么方法可以仅基于发布配置文件(不通过帐户登录)来调用Publish-AzWebApp?

不,您不能。如果要使用Publish-AzWebApp,则始终需要使用Connect-AzAccount登录,无论使用什么参数,例如here

如果您要使用Powershell仅基于发布配置文件部署Web应用,则解决方法是use Kudu API via powershell

$username = "`$webappname"
$password = "xxxxxxx"
# Note that the $username here should look like `SomeUserName`, and **not** `SomeSite\SomeUserName`
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"

$apiUrl = "https://joywebapp.scm.azurewebsites.net/api/zipdeploy"
$filePath = "C:\Users\joyw\Desktop\testdep.zip"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST -InFile $filePath -ContentType "multipart/form-data"