我想用Bamboo(持续集成解决方案)进行自动部署。我在这里(http://www.windowsazure.com/en-us/develop/net/common-tasks/continuous-delivery/#script)找到了一块脚本来帮忙。主要代码段:
#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."
我刚刚尝试通过执行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"
,从Azure下载publishsettings文件。
但我一直收到错误消息:
New-AzureDeployment:未设置CurrentStorageAccount。使用Set-AzureSubscription子名-CurrentStorageAccount storageaccount来设置它。
它肯定已经在片段中设置了。我甚至试过复制&将Set-AzureSubscription行粘贴到New-AzureDeployment函数内部。没有运气。
救救我!谢谢!
答案 0 :(得分:4)
固定。不知道究竟是什么原因但我通过执行以下命令删除了所有已注册的azure订阅:
PS> Get-AzureSubscription | ForEach-Object { Remove-AzureSubscription $_.SubscriptionName }
并执行以下命令重新导入订阅:
PS> Import-AzurePublishSettingsFile xxx.publishsettings
这一切都奏效了! :)
订阅列表中确实存在一些类似命名的订阅。可能存在冲突,因为天蓝色的脚本不知道他们真正想要哪一个。
答案 1 :(得分:1)
如果您有多个订阅,则需要确保要使用的订阅设置为默认值。这可以通过以下方式完成:
Select-AzureSubscription -SubscriptionName "{subscriptionName}" -Default
如果您不确定订阅名称是什么,可以使用以下内容查看所有订阅:
Get-AzureSubscription