Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created October 8, 2018 06:32
Show Gist options
  • Save OlafD/81afedbeef93931f469aace388e3f1af to your computer and use it in GitHub Desktop.
Save OlafD/81afedbeef93931f469aace388e3f1af to your computer and use it in GitHub Desktop.
Deploy a package for an Azure Web App, generated in Visual Studio, to Azure.
param (
[Parameter(Mandatory=$true)]
[string]$PublishSettingsFile,
[Parameter(Mandatory=$true)]
[string]$DeploymentBatch,
[Parameter(Mandatory=$true)]
[string]$WebAppUrl,
[switch]$Deploy
)
# generate the kudu address for the Azure Web App url
function GetTargetDeploymentUrl
{
param (
[Parameter(Mandatory=$true)]
[string]$Url
)
$result = ""
$i = $Url.IndexOf(".")
if ($i -ge 0)
{
$result = $Url.Insert($i, ".scm")
}
return $result
}
# read the deployment credentials from the publish settings file
[xml]$publishSettings = Get-Content $PublishSettingsFile
$webDeployNode = $publishSettings.SelectSingleNode("/publishData/publishProfile[@publishMethod='MSDeploy']")
$userName = $webDeployNode.userName
$password = $webDeployNode.userPWD
# get the web address to deploy to
$deploymentUrl = GetTargetDeploymentUrl -Url $WebAppUrl
if ($deploymentUrl -eq "")
{
Write-Host -ForegroundColor Red "Cannot generate target deployment url."
}
else
{
# call the deployment batch and perform deployment
Write-Host -ForegroundColor Magenta "Deploy to $deploymentUrl"
$deploymentUrl = $deploymentUrl + "/MSDeploy.axd"
if ($Deploy -eq $True)
{
& $DeploymentBatch /Y "/M:$deploymentUrl" /U:$userName /P:$password /a:Basic
}
else
{
& $DeploymentBatch /T "/M:$deploymentUrl" /U:$userName /P:$password /a:Basic
}
}
Write-Host -ForegroundColor Green "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment