如何使用Powershell中的MSDeploy将Web应用程序zip包部署到Azure?

4
我有一个 Web 应用程序的 zip 包,希望通过 Powershell 脚本调用 MSDeploy 工具从我们的 Jenkins 服务器部署到 Azure 上。
如何操作呢?
1个回答

4
请使用以下脚本:
$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非常脆弱,请参见https://stackoverflow.com/a/25198222


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接