Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS Azure powershell : No default subscription has been designated

I'm trying to run some azure powershell commands as part of my Visual Studio Team Services build using Azure Resource Manager.

It gives me the following error:

No default subscription has been designated. Use Select-AzureSubscription -Default to set the default subscription.

VSTS azure powershell error

The commands I'm trying to run:

$website = Get-AzureWebsite | where {$_.Name -eq 'my-website'}
Write-Output ("##vso[task.setvariable variable=DeployUrl;]$website.HostNames")

When I tried to run it locally, I had to call

Add-AzureAccount
Select-AzureRmSubscription -SubscriptionName "Visual Studio Premium with MSDN"

to get it working, but it is not possible in the VSTS build.

UPDATE:

I've configured it to use the azure classic mode instead of resource manager, at it works. I don't think that it is a feasible solution for production as azure classic mode is obsolete.

like image 661
Herr Kater Avatar asked Dec 19 '22 13:12

Herr Kater


1 Answers

Since you are using Azure Resource Manager, please check the things below:

  1. Make sure "Azure Resource Manager" service endpoint is added correctly.
  2. Use "Get-AzureRmWebApp" command instead of "Get-AzureWebsite" command just as bmoore mentioned.

I have tested it at my side, it works correctly.

My PowerShell script:

$website = Get-AzureRmWebApp | where {$_.Name -eq 'eddieapp0930'}
Write-Host $website.HostNames

Run from "Azure PowerShell Script" task: enter image description here

like image 114
Eddie Chen - MSFT Avatar answered May 12 '23 09:05

Eddie Chen - MSFT