Windows Azure Deployment – Problem and Solution #2

The post is the second post of my “Windows Azure Deployment – Problem and Solution” series. You also read the first post in this link.

Contents

Problem: Issue with multiple Azure subscriptions with same name

Duplicated Subscription Name

The code below is for getting the azure deployment to determine whether we need to publish new package or update the existing page.


$subscription = "[Your Subscription Name]"
$service = "[Your Azure Service Name]"
$slot = "staging" #staging or production
$package = "[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg"
$configuration = "[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg"
$timeStampFormat = "g"
$deploymentLabel = "ContinuousDeploy to $service v%build.number%"

Write-Output "Running Azure Imports"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1"
Import-AzurePublishSettingsFile "C:\TeamCity\[PSFileName].publishsettings"
Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscription

function Publish(){
 $deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

But I got the following error at the line where I call Get-AzureDeployment.

Error Message

VERBOSE: 3:26:54 PM – Begin Operation: Get-AzureDeployment
Get-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 404. Service
Management Error Code: ResourceNotFound. Message: No deployments were found.. Operation Tracking ID:
b27b43c1bf5a47fb97167ede7e364206.”
At C:\BuildAgent\work\e02c76f07d491d1d\scripts\azure_deploy.ps1:57 char:27
+ $completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot
+ ~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureDeployment], ServiceManagementClientException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.GetAzureDeploymentCom
mand

VERBOSE: 3:26:54 PM – Completed Operation: Get-AzureDeployment

Solution

I tried deploying the project from Visual Studio a couple of times and sometimes, the publish wizard can’t detect the service that I created so I assumed that both Azure powershell cmdlet and the publish wizard from VS got the same issue. then I realized that it is because I have multiple subscription that have the same name.. Surprisingly, the most of Azure API are based on “subscriptionName ” instead of the name.. ( man.. there are a lot of funny stuffs in Azure but I can see that there are a lot of improvements being done during this year.. )

The solution for this issue is that you need to set the id when you call Set-AzureSubscription API. The updated code will be looked like that below.


$subscriptionId = "[Your Subscription Id]"
$subscriptionName = "[Your Subscription Name]"

$service = "[Your Azure Service Name]"
$slot = "staging" #staging or production
$package = "[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg"
$configuration = "[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg"
$timeStampFormat = "g"
$deploymentLabel = "ContinuousDeploy to $service v%build.number%"

Write-Output "Running Azure Imports"
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1"
Import-AzurePublishSettingsFile "C:\TeamCity\[PSFileName].publishsettings"
Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId

function Publish(){
$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

Problem: CurrentStorageAccount is not set

data servers

The error message that I got is “Current storage account is not set”. It’s a bit misleading because as you can see in the code below (esp: last line), I did set the current storage but why did I get this message?

Error Message

New-AzureDeployment : CurrentStorageAccount is not set. Use Set-AzureSubscription subname -CurrentStorageAccount
storageaccount to set it.
At C:\BuildAgent\work\e02c76f07d491d1d\scripts\azure_deploy.ps1:55 char:15
+ $opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $ …
+ ~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureDeployment], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCom
mand

Solution

The problem was that I have many subscription accounts and I created the storage account in wrong subscription account. The solution is just to create new storage account in correct subscription account from Azure web console.

Problem: Authentication and Certificate Issues

Security

The error message that I got is “Current storage account is not set”. It’s a bit misleading because as you can see in the code below (esp: last line), I did set the current storage but why did I get this message?

Error Messages

New-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 403. Service
Management Error Code: AuthenticationFailed. Message: The server failed to authenticate the request. Verify that the
certificate is valid and is associated with this subscription.. Operation Tracking ID: <NONE>.”
At line:1 char:1
+ New-AzureDeployment -Slot “staging” -Package “MyProject.Azure\bin\Release\app.publish …
+ ~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureDeployment], ServiceManagementClientException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCommand

New-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 400. Service
Management Error Code: BadRequest. Message: The certificate with thumbprint 426bed136649263b9a154f5fdc1f2707a6ecf482
was not found.. Operation Tracking ID: f5925a7eb5a44dcf8c56c6e950cc8229.”
At C:\BuildAgent\work\e02c76f07d491d1d\Scripts\azure_deploy.ps1:62 char:15
+ $opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $ …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureDeployment], ServiceManagementClientException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.NewAzureDeploymentCom
mand

Solution #1

  • Add-AzureCertificate -serviceName <CLOUDSERVICENAME> -certToDeploy (get-item cert:\CurrentUser\MY\<THUMBPRINT>)
  • Add-AzureCertificate -serviceName hivewebrole -certToDeploy (get-item “cert:\Local Machine\Personal\426BED136649263B9A154F5FDC1F2707A6ECF482”)

And need to pass the certificate information from powershell script. I will show you the updated script later.

Solution #2

It doesn’t matter which solution you choose. You will still need to pass the cert from your script.

Here is the updated script that contains the code for passing the cert.


$thumbprint = &quot;[The tumbprint of your certificate.]&quot;
$myCert = Get-Item cert:\\CurrentUser\My\$thumbprint

$subscriptionId = &quot;[Your Subscription Id]&quot;
$subscriptionName = &quot;[Your Subscription Name]&quot;

$service = &quot;[Your Azure Service Name]&quot;
$slot = &quot;staging&quot; #staging or production
$package = &quot;[ProjectName]\bin\[BuildConfigName]\app.publish\[ProjectName].cspkg&quot;
$configuration = &quot;[ProjectName]\bin\[BuildConfigName]\app.publish\ServiceConfiguration.Cloud.cscfg&quot;
$timeStampFormat = &quot;g&quot;
$deploymentLabel = &quot;ContinuousDeploy to $service v%build.number%&quot;

Write-Output &quot;Running Azure Imports&quot;
Import-Module &quot;C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\*.psd1&quot;
Import-AzurePublishSettingsFile &quot;C:\TeamCity\[PSFileName].publishsettings&quot;

Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId -Certificate $myCert

Write-Output &quot;Set-AzureSubscription&quot;

function Publish(){
$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue

Additional, you might get the error below when you import the Azure publish setting file after making changes in certificate.

PS C:\Windows\system32> Import-AzurePublishSettingsFile “C:\Users\root\Downloads\Visual Studio Ultimate with MSDN-Windows
Azure MSDN – Visual Studio Ultimate-BizSpark–credentials.publishsettings”
Import-AzurePublishSettingsFile : No certificate was found in the certificate store with thumbprint
EB3E353EE50CB344F246D0D975557CBAB1C38494
At line:1 char:1
+ Import-AzurePublishSettingsFile “C:\Users\root\Downloads\Visual Studio Ultimate w …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Import-AzurePublishSettingsFile], ArgumentException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.Subscription.ImportAzurePublishSettingsCommand

The solution for that you need to do either one of them that I listed below.

  • Close and re-open the powershell  — OR —
  • Delete all files under C:\Users\[User]\AppData\Roaming\Windows Azure Powershell,   — OR —
  • Restart the server

Problem: Server Busy

DDos attack

( Yes. I captured the screenshot of “DDoS Attack Visualization” video from Logstalgia  because it’s pretty cool. You should go and check out the project as well. )

But no. Windows Azure wasn’t under DDOS attack.

Error Message

Set-AzureDeployment : “An exception occurred when calling the ServiceManagement API. HTTP Status Code: 503. Servi
Management Error Code: ServerBusy. Message: The server is currently unavailable to receive requests. Please retry
request.. Operation Tracking ID: 9b4dfd5616b34c87bfaf6f808a9d22be.”
At C:\BuildAgent\work\e02c76f07d491d1d\Scripts\azure_deploy.ps1:77 char:22
+ $setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package $package …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureDeployment], ServiceManagementClientException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.ServiceManagement.HostedServices.SetAzureDeploymemand

Solution

The only solution is that you need to wait a bit and try to deploy it again.

I think that’s pretty much it.. I haven’t played around with SDK 2.2 yet.. I will leave this series open and if I got something new then I will post it here again..

Thanks!

3 thoughts on “Windows Azure Deployment – Problem and Solution #2

Leave a Reply

Your email address will not be published. Required fields are marked *