3
votes

We publish to our Azure Web App using MSBuild MSDeploy in VSO/VSTS Build (vNext) using the script below. This works well.

BUT, when assigning the Azure Web App to a custom domain (through the Azure Portal), the publish fails.

VSTS Build error on MSDeploy:

Publishing with publish method [MSDeploy] Executing command ["C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:IisApp='C:\a\8b0700fff\MrProjectMain\Api\wwwroot' -dest:IisApp='myproject-prod-webapp',ComputerName='https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd',UserName='$myproject-prod-webapp',Password='{PASSWORD-REMOVED-FROM-LOG}',IncludeAcls='False',AuthType='Basic' -verb:sync -enableLink:contentLibExtension -retryAttempts:2 -disablerule:BackupRule]
[error]Error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC
[error]More Information: Could not connect to the remote computer ("myproject-prod-webapp.azurewebsites.net") using the specified process ("Web Management Service") because the server did not respond. Make sure that the process ("Web Management Service") is started on the remote computer. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_COULD_NOT_CONNECT_TO_REMOTESVC. [error]Error: The remote server returned an error: (403) Forbidden.
[error]Error count: 1.

Azure portal custom domain setup:

Azure Portal Custom domain

Publish script:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword;
                        'SkipExtraFilesOnServer'='False';
                        'AllowUntrustedCertificate'='True'}

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"
. $publishScript -publishProperties $publishProperties  -packOutput $packOutput
1

1 Answers

1
votes

The issue is here:

$msdeployurl = $website.EnabledHostNames[1]

By default, the MSDeploy SCM URL is the second in the EnabledHostNames array. So it works by default. But it may not work as soon as you made some changes to your web app. According to the logs you provided, MSDeploy is trying to connect to "https://myproject-prod-webapp.azurewebsites.net/msdeploy.axd", this is not a SCM URL. The SCM URL should like this: "https://myproject-prod-webapp.scm.azurewebsites.net/msdeploy.axd". So you need to check what is the correct scm URL array number now. You can add the code like following in the PowerShell script to see which one is the scm URL and then update the script accordingly.

Write-Output $website.EnabledHostNames[0]
Write-Output $website.EnabledHostNames[1]
Write-Output $website.EnabledHostNames[2]
...

You can also refer to this article to update your script to get the correct SCM url automatically.