Skip to content

Instantly share code, notes, and snippets.

@mjul
Created October 22, 2018 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjul/3b26bcbfbd03bbacf05d3aa96f2eee90 to your computer and use it in GitHub Desktop.
Save mjul/3b26bcbfbd03bbacf05d3aa96f2eee90 to your computer and use it in GitHub Desktop.
Azure DevOps (VSTS) Get Azure WebApp DefaultHostName workaround
# Get-AzureRmWebApp does not work correctly when running under the Azure DevOps build server (October 2018).
# Here is a workaround to get the DefaultHostName
# Place your own name here:
$appName = "myspecialappname-dev"
$webApp = Get-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $appName -ErrorAction Stop
if (!$webApp) { Write-Error ("WebApp not found: {0} (Resource Group: {1})" -f $appName,$ResourceGroupName) }
# DefaultHostName property does not work in the Azure DevOps (VSTS) build server, see: https://github.com/Azure/azure-powershell/issues/5760
# The HostNames property works, so pick one of the hostnames instead of DefaultHostName:
foreach ($name in $webApp.HostNames) {
if ($name.ToLower().StartsWith($appName.ToLower())) {
$hostname = $name;
break;
}
}
if (!$hostname) { Write-Error ("HostName not found for WebApp: {0} (Resource Group: {1})" -f $appName,$ResourceGroupName) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment