4

I have a zip package of web app that I want to deploy to Azure from our Jenkins server using MSDeploy tool invoked from Powershell script.

How to do it?

1 Answer 1

4

Use the following script:

$PackagePath = "c:\temp\package.zip"
$ResourceGroupName = "resource-group-where-my-app-resides"
$AppName = "my-cool-web-app"

if (!(Test-Path $PackagePath)) {
  throw "Package file $PackagePath does not exist"
}

echo "Getting publishing profile for $AppName app"
$xml = Get-AzureRmWebAppPublishingProfile -Name $AppName `
           -ResourceGroupName $ResourceGroupName `
           -OutputFile temp.xml -Format WebDeploy -ErrorAction Stop
$username = ([xml]$xml).SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@userName").value
$password = ([xml]$xml).SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@userPWD").value
$url = ([xml]$xml).SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@publishUrl").value
$siteName = ([xml]$xml).SelectNodes("//publishProfile[@publishMethod=`"MSDeploy`"]/@msdeploySite").value
del temp.xml
echo "Got publishing profile XML."

$msdeployArguments = 
    '-verb:sync ' +
    "-source:package='$PackagePath' " + 
    "-dest:auto,ComputerName=https://$url/msdeploy.axd?site=$siteName,UserName=$username,Password=$password,AuthType='Basic',includeAcls='False' " +
    "-setParam:name='IIS Web Application Name',value=$siteName"
$commandLine = '&"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" --% ' + $msdeployArguments
Invoke-Expression $commandLine

msdeploy.exe is very brittle with spaces in command line parameters, see https://stackoverflow.com/a/25198222

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.