1

I am trying to publish a Web App package on an App Service on Azure. I need to crate a Powershell script to run from the Cloud Shell, in order to publish the package. I wrote the following code

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

This code works on my local machine, but not in the Cloud Shell where I get the following errors:

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.

I guess these errors are caused by the fact that these cmdlets comes from the old Classic Manager, which is not available in the Cloud Shell.

Basically I need to publish a Web App package from the Cloud Shell with a script. How can I achieve that? Do I have other options?

Hannel
  • 1,656
  • 3
  • 10
  • 17
user2297037
  • 1,167
  • 2
  • 14
  • 34
  • Just curious, why do you need to publish the Web App package from the Cloud Shell with a script? –  Nov 08 '18 at 20:11
  • 1
    I know it seems strange, but in my case I cannot set up a Continuous Deployment process and I am not the person in charge of publishing the web app. Since I wanted to avoid any kind of problem due to external factors (e.g. missing modules, missing permissions to run scripts...), I decided to create a script that can be executed by another person in the same environment where I tested the script. – user2297037 Nov 09 '18 at 08:53

2 Answers2

2

Steps and commands you are following are for ASM (classic) Website deployment.

Could Shell only have ARM modules and does not have modules that have those command.

Check link below out to see if that works for you.

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

Hope this helps.

Hannel
  • 1,656
  • 3
  • 10
  • 17
  • Hi, Hannel, is it possible to install the ASM module in cloud shell? – Joy Wang Nov 09 '18 at 06:19
  • It use to be but not anymore from the last time i tried. But you can try it yourself, in cloudshell run `Install-Module Azure`. That use to install the module. – Hannel Nov 09 '18 at 06:23
  • I also have tried it, and got an error `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.` So I'm a little confused. May be it is not supported? Have not found some docs about it. – Joy Wang Nov 09 '18 at 06:25
  • 1
    **Yes. it is not supported anymore**. Sorry for the confusion i was trying to give you the full information. You currently cannot install the ASM module on Cloudshell. – Hannel Nov 09 '18 at 06:30
2

Starting from the documentation link suggested by Hannel, I finally solved by invoking REST API with Powershell. With Azure CLI is much easier, but I have a more complex script already written with Powershell.

Final code is this:

# 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
user2297037
  • 1,167
  • 2
  • 14
  • 34