Created
October 22, 2018 12:41
-
-
Save mjul/3b26bcbfbd03bbacf05d3aa96f2eee90 to your computer and use it in GitHub Desktop.
Azure DevOps (VSTS) Get Azure WebApp DefaultHostName workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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