4
votes

I want to do automated deployment with Bamboo (a Continuous Integration solution). I found in here(http://www.windowsazure.com/en-us/develop/net/common-tasks/continuous-delivery/#script) a piece of script to help. The main code snippet:

#configure powershell with Azure 1.7 modules
Import-Module Azure

#configure powershell with publishsettings for your subscription
$pubsettings = $subscriptionDataFile
Import-AzurePublishSettingsFile $pubsettings
Set-AzureSubscription -CurrentStorageAccount $storageAccountName -SubscriptionName $selectedsubscription
write-host $storageAccountName
write-host "$selectedsubscription"

#set remaining environment variables for Azure cmdlets
$subscription = Get-AzureSubscription $selectedsubscription
$subscriptionname = $subscription.subscriptionname
$subscriptionid = $subscription.subscriptionid
$slot = $environment

#main driver - publish & write progress to activity log
Write-Output "$(Get-Date –f $timeStampFormat) - Azure Cloud Service deploy script started."
Write-Output "$(Get-Date –f $timeStampFormat) - Preparing deployment of $deploymentLabel for $subscriptionname with Subscription ID $subscriptionid."


Publish

$deployment = Get-AzureDeployment -slot $slot -serviceName $servicename
$deploymentUrl = $deployment.Url

Write-Output "$(Get-Date –f $timeStampFormat) - Created Cloud Service with URL $deploymentUrl."
Write-Output "$(Get-Date –f $timeStampFormat) - Azure Cloud Service deploy script finished."

I just first tried running this script from cmd by executing powershell E:\CI\OCZDeployment\publish_cloud_service.ps1 -environment Staging -serviceName "ocz" -storageAccountName "t2vsoft" -packageLocation OCZ.cspkg -cloudConfigLocation ServiceConfiguration.Cloud.cscfg -subscriptionDataFile E:\CI\OCZDeployment\SubscriptionDataFile.publishsettings -selectedsubscription "Development Subscription"

, where the publishsettings file is downloaded from Azure.

But I kept getting the error message:

New-AzureDeployment : CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount storageaccount to set it.

It has definitely been set in the snippet. I even tried copy & paste the Set-AzureSubscription line to inside New-AzureDeployment function. No luck.

Help me! Thank you!

2

2 Answers

4
votes

Fixed. Don't know what was exactly the cause but i removed all registered azure subscriptions by executing:

PS> Get-AzureSubscription | ForEach-Object { Remove-AzureSubscription $_.SubscriptionName }

and re-imported the subscription by executing:

PS> Import-AzurePublishSettingsFile xxx.publishsettings

and it all worked! :)

There really were some similarly-named subscriptions in the subscription list. There might have been conflicts as such the azure scripts didn't know which one they really wanted.

1
votes

If you have multiple subscriptions then you need to make sure the subscription that you want to use is set to the default. This can be done with the following:

Select-AzureSubscription -SubscriptionName "{subscriptionName}" -Default

if you aren't sure what your subscription name is you can use the following to see all of your subscriptions:

Get-AzureSubscription