Reputation: 1217
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?
Upvotes: 1
Views: 1845
Reputation: 1217
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
Upvotes: 2
Reputation: 1706
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.
Upvotes: 2