Search code examples
azurepowershellweb-deploymentazure-web-app-service

How do I deploy to Azure App Service with PowerShell (az module)?


I want to deploy app services from Powershell. I would like to use only publish profile (no password for azure account).

I tried FTP service, but sometimes files are blocked by running users. I think I have to stop app service.

There is powershell command like:

Publish-AzWebApp

However first I need login with:

Connect-AzAccount

and pass credentials what I want to avoid.

There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

Connect-AzAccount has other options to login (token or certificate). Unfortunately I don't know how to generate it.

BTW There was a topic about it: How do I deploy to Azure App Service with PowerShell? But it is old and now module "az" is recommended.


Solution

  • There is any way to call Publish-AzWebApp based on only publish profile (no login by account)?

    No, you can't. If you want to use the Publish-AzWebApp , you always need to login with Connect-AzAccount, whatever the parameters you use, examples here.

    If you want to use powershell to deploy the web app based on only publish profile, the workaround is to 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"