Search code examples
azureazure-web-app-serviceazure-cloud-shellpublish-profiles

Azure Cloud shell to publish Web App using publish profile


The Azure Cloud Shell can not import the publish profile (i.e. "MyWebApp.PublishSettings") that can be exported from the overview of the web app in Azure, which can be used in Visual Studio to publish the web app. I am trying to find the commands to execute with the Azure Cloud Shell (az webapp up ... perhaps), but it requires me to sign in first, using az login .... For Visual Studio the publish profile file is enough and no login is required. How can I publish like Visual Studio does using the publish profile, but using the Azure Cloud Shell?


Solution

  • I am trying to find the commands to execute with the Azure Cloud Shell (az webapp up ... perhaps), but it requires me to sign in first, using az login ...

    When you using the azure cloud shell, it automatically uses the account which logged in the azure portal, so no need to login with az login again, just use the command az webapp up directly. And you should note, the command az webapp up is required to run from the folder where the code is present, so you may need to upload your code to the cloud shell first(I have not tested it, not sure if it works in the cloud shell.)

    enter image description here

    Actually, if you want to deploy the webapp using publish profile, the easiest way I recommend is to use the kudu api via powershell in local, just open a powershell session in local and run the commands below, you can find the $password in the publish profile.

    $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"