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.

IronWilliamCash
  • 539
  • 5
  • 19
  • Are you looking to deploy your website as a Web Deploy Package to the Azure App Service site? – juvchan Aug 24 '17 at 02: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. – IronWilliamCash Aug 24 '17 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 – juvchan Aug 24 '17 at 13:33
  • @juvchan : Got this to work with the answer from Walter, but thanks for the help! – IronWilliamCash Aug 24 '17 at 16:56

4 Answers4

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"
IronWilliamCash
  • 539
  • 5
  • 19
Shui shengbao
  • 18,746
  • 3
  • 27
  • 45
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

Jay
  • 2,648
  • 4
  • 29
  • 58
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
RuudvK
  • 635
  • 5
  • 9
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
KaranSingh
  • 460
  • 4
  • 11