6

I have looked around and with the thousands of commands in the Azure and AzureRM commandlets in PowerShell, I'm still not sure how to do this.

What I have working so far:

  • Installed Azure and AzureRM modules and imported them to the script
  • Generated the "*.publishsettings" file from the get-AzurePublishSettingsFile command
  • Imported the "*.publishsettings" file
  • Can acccess the website with the "Stop-AzureWebsite" and "Start-AzureWebsite" commandlets

What I need to do:

  • create a new deployment and push files to the app-service site.

Notes: I do not have a Visual Studio project and .csproj file configs. I simply want to take the contents of a folder and push that to the website.

Any help would be useful as the documentation is really bad on details and there are thousands of commands in PowerShell to go through.

4
  • Are you looking to deploy your website as a Web Deploy Package to the Azure App Service site? Commented Aug 24, 2017 at 2:41
  • @juvchan : It's basically just a bunch of files (mostly *.js, *.css and *.html) not as a package. I can zip them if need be, but they aren't part of a VS project or other. Commented Aug 24, 2017 at 13:28
  • 1
    The steps would be straightforward if you know how to package your website files into Web Deploy package using msdeploy command, I will be able to guide you from there if this solution sounds viable to you Commented Aug 24, 2017 at 13:33
  • @juvchan : Got this to work with the answer from Walter, but thanks for the help! Commented Aug 24, 2017 at 16:56

4 Answers 4

8

You could check this blog:Deploy an App Service using Azure PowerShell to a Deployment Slot.

Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile .\Your-Publish-Settings-credentials.publishsettings
Get-AzureSubscription
Select-AzureSubscription -SubscriptionName "The Subscription Name containing the slot"
Set-AzureSubscription -SubscriptionId "ID of subscription"

$WebAppName = "standard(staging)"
Get-AzureWebsite -Name $WebAppName
Publish-AzureWebsiteProject -Name $WebAppName -Package "C:\PowerShell\standard.zip" -Slot "staging"
Sign up to request clarification or add additional context in comments.

2 Comments

So I can use the "Publish-AzureWebsiteProject" and passi it a zip file as the Package? All the documentation I saw mentionned "*.csporj" packages.
Just coming back to confirm that this worked with a zip file. Finally fixed the issue. Thanks for the help
3

The above link (https://blogs.msdn.microsoft.com/benjaminperkins/2016/10/01/deploy-an-app-service-using-azure-powershell-to-a-deployment-slot/)talks about a GIT based deployment. OP wanted something from a folder.

Check this one out -

Create an Azure Website with PowerShell and FTP

3 Comments

Saying "The above link" doesn't make sense in Stackoverflow. The page will shuffle the answers around with each refresh.
Still learning the ropes. I have included the link I was talking about. thanks for correcting.
@Jay This would have been my backup solution. Thanks for the info, but I got it to work with ­Walters answer.
2

Unfortunately the accepted answer gave me the following error:

Get-AzureWebSite : Requested value 'PremiumV2' was not found

This StackOverflow answer suggests to use Get-AzureRmWebApp instead, but this introduces some challenges with authentication. After some searching I found the following article which explained exactly what I needed: an approach to do a publish to Azure without any human interaction.

Please see a very simplified version of the script below.

#In the Azure portal go to (search for) "Azure Active Directory" -> 
#"Properties" -> Directory ID
$TenantId = "<Azure Active Directory Id>"

#In the Azure portal go to (search for) "Subscriptions" -> Subscription ID
$SubscriptionId = "<Azure Subscription Id>"

#In the Azure portal go to (search for) "Azure Active Directory" -> "App registrations" -> 
#Create a new registration, this will give you the ID and Secret below.
#Make sure to give your new app registration sufficient rights to your app service 
$ServicePrincipleApplicationId = "<Service Principle Id>"
$ServicePrincipleApplicationSecret = "<Service Principle Secret>"

$WebAppPath = "<Local folder where your package is located>"
$ResourceGroupName = "<The name of the Azure resource group that contains your app service>"
$WebAppName = "<The name of your Azure app service>"
$WebAppSlot = "<The name of the deployment slot you want to publish to>"

$MSDeployPath = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$source = "-source:contentPath=$WebAppPath"
$publishProfileOutputPath = Join-Path -Path $ENV:Temp -ChildPath 'publishprofile.xml'
$dest = "-dest:contentPath=d:\home\site\wwwroot\,publishSettings=$publishProfileOutputPath"
$SecurePassword = $ServicePrincipleApplicationSecret | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ServicePrincipleApplicationId, $securePassword
$connectParameters = @{
    Credential     = $Credential
    TenantId       = $TenantId
    SubscriptionId = $SubscriptionId
}

Add-AzureRmAccount @connectParameters -ServicePrincipal

Get-AzureRmWebAppSlotPublishingProfile -OutputFile $publishProfileOutputPath -Format WebDeploy -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

Stop-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

& $MSDeployPath @('-verb:sync', $source, $dest)

Start-AzureRmWebAppSlot -ResourceGroupName $ResourceGroupName -Name $WebAppName -Slot $WebAppSlot

Comments

0

To deploy your zip package to Azure Web App Service using PowerShell cmdlet. Refer MS Docs.

Connect to Azure Subscription via PowerShell. Execute Publish-AzWebApp to deploy Web App.

$webAppName = "<NameOfWebAppService>"
$resourceGroup = "<WebAppResourceGroupName>"
$zipArchiveFullPath = "<zip-package-filePath\FileName.zip>"
Publish-AzWebApp -ResourceGroupName "$resourceGroup" -Name "$webAppName" -ArchivePath "$($zipArchiveFullPath)" -Force

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.