我需要从powershel脚本到Azure的部署包(mvc站点)。但是当我启动脚本时,我发现它不起作用。 powershell表明Azure Cloud Service部署脚本已完成,但实际上并没有任何变化。你能帮我解决一下吗? 这是我的powershell命令:
PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> PowerShell C:\scripts\WindowsAzur
e\PublishCloudApp.ps1 -environment Production -enableDeploymentUpgrade 1 -servic
eName testLocalAzure -storageAccountName testcloudservice -packageLocation C:\dr
ops\app.publish\WindowsAzureC.cspkg -cloudConfigLocation C:\drops\app.publish\Se
rviceConfiguration.Cloud.cscfg -subscriptionDataFile C:\scripts\WindowsAzure\def
aul.publishsettings
1/13/2014 1:12 AM - Azure Cloud Service deploy script started.
1/13/2014 1:12 AM - Preparing deployment of ContinuousDeploy to testLocalAzure
for default with Subscription ID .
1/13/2014 1:12 AM - Deployment exists in testLocalAzure. Upgrading deployment.
1/13/2014 1:12 AM - Upgrading Deployment: In progress
Set-AzureDeployment : CurrentStorageAccountName is not set. Use
Set-AzureSubscription subname -CurrentStorageAccountName storageaccount to set
it.
At C:\scripts\WindowsAzure\PublishCloudApp.ps1:78 char:22
+ $setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package
$packageL ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : NotSpecified: (:) [Set-AzureDeployment], Argumen
tException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.WindowsAzure.
Commands.ServiceManagement.HostedServices.SetAzureDeploymentCommand
1/13/2014 1:12 AM - Upgrading Deployment: Complete, Deployment ID: 1d90a71030f4
437bab45b21de76ec308
1/13/2014 1:12 AM - Created Cloud Service with URL http://testlocalazure.clouda
pp.net/.
1/13/2014 1:12 AM - Azure Cloud Service deploy script finished.
PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0>
这是脚本,我称之为:
Param( $serviceName = "",
$storageAccountName = "",
$packageLocation = "",
$cloudConfigLocation = "",
$environment = "Staging",
$deploymentLabel = "ContinuousDeploy to $servicename",
$timeStampFormat = "g",
$alwaysDeleteExistingDeployments = 1,
$enableDeploymentUpgrade = 1,
$selectedsubscription = "default",
$subscriptionDataFile = ""
)
function Publish()
{
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue
if ($a[0] -ne $null)
{
Write-Output "$(Get-Date –f $timeStampFormat) - No deployment is detected. Creating a new deployment. "
}
#check for existing deployment and then either upgrade, delete + deploy, or cancel according to $alwaysDeleteExistingDeployments and $enableDeploymentUpgrade boolean variables
if ($deployment.Name -ne $null)
{
switch ($alwaysDeleteExistingDeployments)
{
1
{
switch ($enableDeploymentUpgrade)
{
1 #Update deployment inplace (usually faster, cheaper, won't destroy VIP)
{
Write-Output "$(Get-Date –f $timeStampFormat) - Deployment exists in $servicename. Upgrading deployment."
UpgradeDeployment
}
0 #Delete then create new deployment
{
Write-Output "$(Get-Date –f $timeStampFormat) - Deployment exists in $servicename. Deleting deployment."
DeleteDeployment
CreateNewDeployment
}
} # switch ($enableDeploymentUpgrade)
}
0
{
Write-Output "$(Get-Date –f $timeStampFormat) - ERROR: Deployment exists in $servicename. Script execution cancelled."
exit
}
} #switch ($alwaysDeleteExistingDeployments)
} else {
CreateNewDeployment
}
}
function CreateNewDeployment()
{
write-progress -id 3 -activity "Creating New Deployment" -Status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Creating New Deployment: In progress"
$opstat = New-AzureDeployment -Slot $slot -Package $packageLocation -Configuration $cloudConfigLocation -label $deploymentLabel -ServiceName $serviceName
$completeDeployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
write-progress -id 3 -activity "Creating New Deployment" -completed -Status "Complete"
Write-Output "$(Get-Date –f $timeStampFormat) - Creating New Deployment: Complete, Deployment ID: $completeDeploymentID"
StartInstances
}
function UpgradeDeployment()
{
write-progress -id 3 -activity "Upgrading Deployment" -Status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Upgrading Deployment: In progress"
# perform Update-Deployment
$setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package $packageLocation -Configuration $cloudConfigLocation -label $deploymentLabel -ServiceName $serviceName -Force
$completeDeployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$completeDeploymentID = $completeDeployment.deploymentid
write-progress -id 3 -activity "Upgrading Deployment" -completed -Status "Complete"
Write-Output "$(Get-Date –f $timeStampFormat) - Upgrading Deployment: Complete, Deployment ID: $completeDeploymentID"
}
function DeleteDeployment()
{
write-progress -id 2 -activity "Deleting Deployment" -Status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Deleting Deployment: In progress"
#WARNING - always deletes with force
$removeDeployment = Remove-AzureDeployment -Slot $slot -ServiceName $serviceName -Force
write-progress -id 2 -activity "Deleting Deployment: Complete" -completed -Status $removeDeployment
Write-Output "$(Get-Date –f $timeStampFormat) - Deleting Deployment: Complete"
}
function StartInstances()
{
write-progress -id 4 -activity "Starting Instances" -status "In progress"
Write-Output "$(Get-Date –f $timeStampFormat) - Starting Instances: In progress"
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$runstatus = $deployment.Status
if ($runstatus -ne 'Running')
{
$run = Set-AzureDeployment -Slot $slot -ServiceName $serviceName -Status Running
}
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$oldStatusStr = @("") * $deployment.RoleInstanceList.Count
while (-not(AllInstancesRunning($deployment.RoleInstanceList)))
{
$i = 1
foreach ($roleInstance in $deployment.RoleInstanceList)
{
$instanceName = $roleInstance.InstanceName
$instanceStatus = $roleInstance.InstanceStatus
if ($oldStatusStr[$i - 1] -ne $roleInstance.InstanceStatus)
{
$oldStatusStr[$i - 1] = $roleInstance.InstanceStatus
Write-Output "$(Get-Date –f $timeStampFormat) - Starting Instance '$instanceName': $instanceStatus"
}
write-progress -id (4 + $i) -activity "Starting Instance '$instanceName'" -status "$instanceStatus"
$i = $i + 1
}
sleep -Seconds 1
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
}
$i = 1
foreach ($roleInstance in $deployment.RoleInstanceList)
{
$instanceName = $roleInstance.InstanceName
$instanceStatus = $roleInstance.InstanceStatus
if ($oldStatusStr[$i - 1] -ne $roleInstance.InstanceStatus)
{
$oldStatusStr[$i - 1] = $roleInstance.InstanceStatus
Write-Output "$(Get-Date –f $timeStampFormat) - Starting Instance '$instanceName': $instanceStatus"
}
$i = $i + 1
}
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot $slot
$opstat = $deployment.Status
write-progress -id 4 -activity "Starting Instances" -completed -status $opstat
Write-Output "$(Get-Date –f $timeStampFormat) - Starting Instances: $opstat"
}
function AllInstancesRunning($roleInstanceList)
{
foreach ($roleInstance in $roleInstanceList)
{
if ($roleInstance.InstanceStatus -ne "ReadyRole")
{
return $false
}
}
return $true
}
# specify path for Azure module (anyone knows how to configure PSModuleuPath?)
$env:PSModulePath=$env:PSModulePath+";"+"C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell"
#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
#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."
答案 0 :(得分:2)
-CurrentStorageAccountName ,您将其作为-CurrentStorageAccount与Set-AzureSubscription cmdlet一起使用。所以包括名称。
答案 1 :(得分:0)
错误几乎告诉你发生了什么(粗体是我的) -
1/13/2014 1:12 AM - 升级部署:正在进行中 Set-AzureDeployment:未设置CurrentStorageAccountName。 使用 Set-AzureSubscription子名称-CurrentStorageAccountName要设置的storageaccount 它强>
在脚本运行的上下文中,未设置要使用的默认存储帐户。
您可以使用Set-AzureSubscription
设置它,我看不到您在脚本中的任何位置调用它。
答案 2 :(得分:0)
链接到原始脚本:http://www.windowsazure.com/en-us/documentation/articles/cloud-services-dotnet-continuous-delivery/
请检查Windows Azure订阅名称:在我的情况下,它不是“默认”。
因此,您必须使用正确订阅的名称编辑脚本中的 $ selectedsubscription 参数。您可以使用Get-AzureSubscription
命令获取它。
答案 3 :(得分:0)
我也遇到了这个问题,结果发现活动订阅没有使用存储信息进行更新。
在Set-AzureSubscription
行之后,您应该添加
Select-AzureSubscription $selectedsubscription