Tips on compiling NuGetGallery source code and hosting it on IIS

Last week, I tried compiling the source code of NuGetGallery and hosting it on IIS but found some issues. Here is the list of issues/solutions that I found. I am sharing it here. Hope it will save some of your times if you are facing the same issues.

Note that I was using the master branch and the date that I downloaded the source from that branch was 22/09/2015.

Azure SDK

The first error that I got was the compile error. It was because I don’t have an Azure SDK on my VM. Well, I know installing the Azure SDK is one of the prerequisites but I am not going to host it on Azure so I decided to change the path of two assemblies below in NuGetGallery.csproj.

  • Microsoft.WindowsAzure.Diagnostics.dll
  • Microsoft.WindowsAzure.ServiceRuntime.dll

NuGet Gallery team shipped those assemblies under lib/AzureSDK so it’s quite easy to change it.

Wrong Path of Azure DLL

Entity Framework 5 + VS2013 Update 5 issue

I got this error when I tried to update the database.

22-09-2015 1-02-14 PM

It looks like a known issue with EF5+VS2013Update but I found the workaround Update-Database throwing “Could not load file or assembly EntityFramework .. or one of its dependencies” error.

The steps below is the workaround to fix this issue.

  • Start VS Command Prompt as Administrator
  • Go to your packages directory and find the EntityFramework package directory.
  • Go to lib\net45
  • Type: gacutil /i EntityFramework.dll
  • Restart Visual Studio

I managed to update the database after I did those steps but I got the runtime error below when I launch the NuGetGallery project.

Failed to set Database.DefaultConnectionFactory to an instance of the ‘System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework’ type as specified in the application configuration. See inner exception for details.

{“Could not load file or assembly ‘EntityFramework’ or one of its dependencies. The system cannot find the file specified.”:”EntityFramework”}

so I would suggest that you should uninstall EntityFramework.dll from GAC later.

gacutil /u EntityFramework

RequireSsl

It’s up to you whether you want to have SSL enabled or not. For me, I don’t need it so remove [RequireSsl] attribute from NuGetGallery/Controllers/AuthenticationController.cs.

Remove ReWrite

I don’t want to enable http-rewrite module and when I look at the config, it looks like they are just using it for nuget.org only so I removed the whole re-write session from config.

Remove rewrite

Enable-LocalTestMe

If you are running it from VS, you will have to enable the local test me by running .\Enable-LocalTestMe.ps1 script unless you want to change the configuration manually. but your goal is just to host it on IIS then you don’t have to do it.

Enable_localTestMeinIISExpress

NuGet Push “Method Not Allowed” error

After I manage to run NuGetGallery project, I got another small issue with nuget push.

[16:35:45][push] Failed to process request. ‘Method Not Allowed’.
[16:35:45][push] The remote server returned an error: (405) Method Not Allowed..
[16:35:45][push] Process exited with code 1
[16:35:45][Step 6/6] Step Push To NuGet (NuGet Publish) failed

I removed “WebDEV” from http-handler and module. After that, it works.

 

 

WebDev

I will probably upload the publish file and database schedule later this week or next week.

Deploying the Azure website and Azure webjob from Octopusdeploy (+TeamCity)

Introduction

Last week, it has been a busy week for us but we are glad that managed to bring the Azure WebJobs with Octopus Deploy into one of our small projects. I like to share something that we have learnt and like to get some feedback from you guys.

Azure Web Job

Oh well, Scott Hanselman did a pretty good job on explaining about it in his blog post “Introducing Windows Azure WebJobs” so I am not going to repeat the same thing here. I will just give you a short note on this.

What is Azure Web Job?

It’s a backend job that you want to run it on Azure.  It’s like Windows Service that you run on your machine or the batch job that you used to run from Windows Schedular. There are three triggers points as below~

  1. Azure Storage: You can trigger the Azure webjob to run by sending a message to the blobs, queues or tables in your Azure storage account.
  2. Scheduler: Just like windows scheduler, you can run the web job either one time or on regular basis.
  3. Http/https Endpoint: You can run your web job by accessing this endpoint as well.

What are the different between Azure Web Job Vs Cloud Service (Worker Role) Vs Virtual Machine?

  • VM: You can install your backend job on VM but you need to maintain your VM on your own. (For example: updating OS/Framework update, security patches)
  • Cloud Service: It’s still a VM but is manged by Microsoft so you don’t need to maintain it but still, you might not need a VM to run your backend job.
  • Web Job: It’s like using a shared host. You don’t need to maintain any VM and it got full integration with Azure storage as well. If you are a fan of Azure website, you might like it as well.

Where does it store?

The web job are stored in the following directory.

site\wwwroot\App_Data\jobs\{job type}\{job name}

It’s important to know because we are going to use it later.

Ok. My short note on Azure webjob will end here since it’s not my intention to write about web job in this post. but there are a lot of useful blog posts regarding Azure webjob so I am sure that you can easily google them.

Or, you can read some of my favorite posts below~

Octopus Deploy

Why Octopus? As we have only one production, we don’t need Octopus. I found only one reasons why you will need Octopus Deploy.

That reason is ~

  • Multiple servers deployment: If you have a lot of servers then Octopus tentacle comes in handy. You can easily configure the octopus tentacle on all of your servers and you can deploy it in one shot. That tentacle will take care of synchronizing the deployment to all servers. Cool, huh?

Note: I asked the octopus team just to confirm whether my assumption is correct or not. You can read in this post “What is the main selling point for octopusdeploy?” Yes. my assumption is correct!

In our case, we can actually publish the Azure website directly from CI (Team City) using MSDeploy.

Team City + MS Deploy + Azure Web Site

This is the commandline parameters ~

 /p:Configuration=Release /p:OutputPath=bin
/p:VisualStudioVersion=11.0
/p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://{yourazurewebsite-url}:443/msdeploy.axd /p:AllowUntrustedCertificate=True /p:DeployIisAppPath={your-app-pool-name} /p:MSDeployPublishMethod=WMSVC /p:username={your azure website user name from published setting}/p:password={your azure website password from published setting}

Note: You can get the user name and password from the publish profile from your website dashboard.

quick glance

I wrote about MS deploy for publishing website a while back. “WebDeploy 3 – Error in publishing website to Amazon EC2

Anyways, as everyone is talking about Octopus, I thought it might be a good idea to try and get a taste of it.

So I downloaded the Octopus (2.4.7) which includes Octopus Server (x64), Octopus Tentacle (x64) and TeamCity Plugin.

Team City + Octopus Team City Plugin

I installed Octopus plugin in Teamciy by placing the zip file under <TeamCity Data Directory>/plugins. If you are not sure about the <TeamCity Data Directory> then you can check it out in “Administration->Global Setting” page in TeamCity. The default path is C:\ProgramData\JetBrains\TeamCity . Then restart the service to take effect on new plugin installation.

If your installation is working fine then you will see “Octopus Packing” in “MS Build runner” build step or “VS build runner” build step.

Octopus Packing

Note that Octopus has the limitation on the version number and it doesn’t work if your version is just a single number so you will have to change like “1.0.%build.counter%” in “Build number format” in “General Setting”.

After that, you need to enable the nuget feed in Teamcity administration page.

Enable Nuget in TeamCity

That’s all. If you want to view the step by step instruction then you can check this page “TeamCity + Octopus Deployment

Octopus Server

It was pretty easy to install and configure the Octopus server on my server. Good job, Octopus!

Octopus Tentacle

Obviously, I need the server and TeamCity plugins but why Tentacle?

Oh well, Octopus has another limitation beside the build number. It doesn’t work without Tentacle. I think they didn’t think about the deployment scenario where we, developers, don’t have any server. I asked them here (link) to confirm about this. To workaround this, I have to install “Tentacle” on the server that I am hosting the octopus server and configure it as a machine in Octopus’s Environment page.

Octopus Environment

How to connect TeamCity and Octopus? Yes. You need to add the nuget feed that you enabled in Teamcity by using “Add Feed” button in Octopus Library page.

Octopus External Feed1

 

After that, you can create a new project in Octopus and add the steps in “Process” panel.

Note that there are a few different ways as below to deploy the Azure website and web job.

  • FTP Upload
  • Git push
  • MS Deploy

Even thought I am told that there is an Octopus MSDeploy template, I decided to use the FTP upload in my case. (Yeah, I am not a big fan of git push deployment until now. Sorry! )

Here is the default FTP template that you can use when you are adding the step in “Process”

Upload by FTP Template

 

Here is the step details that you need to fill up for FTP template. Octopus FTP Step Details

You can get about the FTP information of your site or webjob from Azure dashboard.

Remember what we said in “Where does it store” section? The web job are stored in the following location so you will have to point to this directory in your “FTP upload” step.

site\wwwroot\App_Data\jobs\{job type}\{job name}

That’s it.

This is how we are using Team City + Octopus for publishing Azure Web Site and WebJob. What is yours?

Continous Delivery: full script for deploying Azure WebRole and WorkerRole from Powershell

After I posted Windows Azure Deployment – Problem and Solution #1 and Windows Azure Deployment – Problem and Solution #2 here last week, one of my blog readers emailed me whether or not I have the full script for deploying the WebRole or Worker Role on Windows Azure.

Yes. I still have it but I stopped using webrole and worker role because deploying web role or worker role takes so much time (around 20-40 min) which is unacceptable for us. Anyways,  if 20-40 min deployment time is not your concern then sure, you can use it.

I wrote and tested this script with Azure SDK 2.1 on Windows 2012 server.

You can download it from my github repository as well. Here is the link https://github.com/michaelsync/Michael-Sync-s-blog-sample/blob/master/azure_deploy.ps1


#Modified and simplified version of https://www.windowsazure.com/en-us/develop/net/common-tasks/continuous-delivery/

$thumbprint = &quot;{Your Cert's Thumbprint}&quot;
$myCert = Get-Item cert:\\CurrentUser\My\$thumbprint
$subscriptionId = &quot;{Your Subscription Id}&quot;
$subscriptionName = &quot;{Your Subscription Name}&quot;
$webroleservice = &quot;{Your Web Role Name}&quot;
$workerroleservice = &quot;{Your Worker Role Name}&quot;

$slot = &quot;staging&quot; #staging or production

$package = &quot;{Path of your Azure project}\bin\Release\app.publish\{Your Project}.cspkg&quot;
$configuration = {Path of your Azure project}\bin\Release\app.publish\ServiceConfiguration.Cloud.cscfg&quot;

$timeStampFormat = &quot;g&quot;

Write-Output &quot;Running Azure Imports&quot;
Import-Module &quot;C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1&quot;
Import-AzurePublishSettingsFile &quot;{Path where you stored your azure setting\Azure.publishsettings&quot;

function Publish(){
 PublishInternal $webroleservice
 PublishInternal $workerroleservice
}

function PublishInternal($service){

Write-Output &quot;Publising&quot;
 Write-Output $service

Set-AzureSubscription -CurrentStorageAccount $service -SubscriptionName $subscriptionName -SubscriptionId $subscriptionId -Certificate $myCert
 Write-Output &quot;Set-AzureSubscription&quot;
 $deploymentLabel = &quot;ContinuousDeploy to $service v%build.number%&quot;

Write-Output $deploymentLabel

$deployment = Get-AzureDeployment -ServiceName $service -Slot $slot -ErrorVariable a -ErrorAction silentlycontinue
 Write-Output a

if ($a[0] -ne $null) {
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - No deployment is detected. Creating a new deployment. &quot;
 }

 if ($deployment.Name -ne $null) {
 #Update deployment inplace (usually faster, cheaper, won't destroy VIP)
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - Deployment exists in $servicename. Upgrading deployment.&quot;
 UpgradeDeployment $service $deploymentLabel
 } else {
 CreateNewDeployment $service $deploymentLabel
 }
}
function CreateNewDeployment($service, $deploymentLabel)
{
 write-progress -id 3 -activity &quot;Creating New Deployment&quot; -Status &quot;In progress&quot;
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - Creating New Deployment: In progress&quot;

$opstat = New-AzureDeployment -Slot $slot -Package $package -Configuration $configuration -label $deploymentLabel -ServiceName $service

$completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot
 $completeDeploymentID = $completeDeployment.deploymentid

write-progress -id 3 -activity &quot;Creating New Deployment&quot; -completed -Status &quot;Complete&quot;
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - Creating New Deployment: Complete, Deployment ID: $completeDeploymentID&quot;
}

function UpgradeDeployment($service, $deploymentLabel)
{
 write-progress -id 3 -activity &quot;Upgrading Deployment&quot; -Status &quot;In progress&quot;
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - Upgrading Deployment: In progress&quot;

# perform Update-Deployment
 $setdeployment = Set-AzureDeployment -Upgrade -Slot $slot -Package $package -Configuration $configuration -label $deploymentLabel -ServiceName $service -Force

$completeDeployment = Get-AzureDeployment -ServiceName $service -Slot $slot
 $completeDeploymentID = $completeDeployment.deploymentid

write-progress -id 3 -activity &quot;Upgrading Deployment&quot; -completed -Status &quot;Complete&quot;
 Write-Output &quot;$(Get-Date -f $timeStampFormat) - Upgrading Deployment: Complete, Deployment ID: $completeDeploymentID&quot;
}

Write-Output &quot;Create Azure Deployment&quot;
Publish

Here is the log for deploying webrole from Visual Studio.

New Deployment

10:56:32 PM – Warning: There are package validation warnings.
10:56:32 PM – Checking for Remote Desktop certificate…
10:56:33 PM – Uploading Certificates…
10:56:51 PM – Preparing deployment for MvcApplication1.Azure – 10/7/2013 10:56:06 PM with Subscription ID ‘1775dfasa8a81fd58’ using Service Management URL ‘https://management.core.windows.net/’…
10:56:51 PM – Connecting…
10:56:51 PM – Verifying storage account ‘mymvctestx01’…
10:56:52 PM – Uploading Package…
11:04:04 PM – Creating…
11:04:54 PM – Created Deployment ID: 337b850dfa3c4dd38dd35441b5b8e337.
11:04:54 PM – Instance 0 of role MvcApplication1 is stopped
11:04:55 PM – Starting…
11:05:45 PM – Initializing…
11:05:45 PM – Instance 0 of role MvcApplication1 is creating the virtual machine
11:06:18 PM – Instance 0 of role MvcApplication1 is starting the virtual machine
11:07:57 PM – Instance 0 of role MvcApplication1 is busy
11:09:37 PM – Instance 0 of role MvcApplication1 is ready
11:09:37 PM – Created Website URL: http://mymvctestx01.cloudapp.net/
11:09:37 PM – Complete.

Upgrading

11:12:40 PM – Warning: There are package validation warnings.
11:12:40 PM – Checking for Remote Desktop certificate…
11:12:42 PM – Preparing deployment for MvcApplication1.Azure – 10/7/2013 11:12:14 PM with Subscription ID ‘17751asdfs8a81fd58’ using Service Management URL ‘https://management.core.windows.net/’…
11:12:42 PM – Connecting…
11:12:42 PM – Verifying storage account ‘mymvctestx01’…
11:12:44 PM – Uploading Package…
11:20:08 PM – Updating…
11:23:19 PM – Instance 0 of role MvcApplication1 is ready
11:23:21 PM – Starting…
11:23:39 PM – Initializing…
11:23:40 PM – Created Website URL: http://mymvctestx01.cloudapp.net/
11:23:40 PM – Complete.

Generally, it takes around 10 to 20 mins but sometimes, it takes around 40 mins. I am not the only one who experienced this problem. You search about it online. Hope that Azure team will do something about it.

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 = &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 $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 = &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

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!

Windows Azure Deployment – Problem and Solution #1

Note: I will start posting the series of “Problem/Solution” posts for Windows Azure deployment. As I intend to reach out to those people who have the same problem and search in Google or Bing, I will post the code, error message, output message  in details. Hence, that will make the post longer but I already told you about my intention. If you like to share your experience with Azure (esp: deployment), please feel free to share with me. 

Scott wrote a great post “CI DEPLOYMENT OF AZURE WEB ROLES USING TEAMCITY” about deploying Azure webrole from Azure PowerShell SDK. I used it as a reference when I was deploying one website and windows service to Azure web role and woker role but due to my settings that Scott might not have, I have to update a few things for his script. I am sharing it here for those who might have the same setting as I have.

Contents

Note: ScottGu announced about the release of Windows Azure SDK 2.2 (Please refer to this link Windows Azure: Announcing release of Windows Azure SDK 2.2 (with lots of goodies) for more information a few days back. But that version wasn’t available when I was playing around with Azure. All API that I used and the experience that I had comes from SDK 2.1.

Problem: Error in importing the module

You need to import the Azure module before you start doing anything with Azure CmdLet but if there is more than


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

Error Message

Import-Module : Path cannot be processed because it resolved to more than one file; can process only one file at a
time.
At line:1 char:1
+ Import-Module “C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Az …
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Collecti…[System.String]:Collection`1) [Import-Module], Runt
imeException
+ FullyQualifiedErrorId : AmbiguousPath,Microsoft.PowerShell.Commands.ImportModuleCommand

Import-Azure

Solution

Use Azure.psd1 instead.


Write-Output &quot;Running Azure Imports&quot;
Import-Module &quot;C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1&quot;

Output
PS C:\> Import-Module “C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1”
VERBOSE: Loading module from path ‘C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1’.
VERBOSE: Importing cmdlet ‘Add-AzureCacheWorkerRole’.
VERBOSE: Importing cmdlet ‘Add-AzureCertificate’.
VERBOSE: Importing cmdlet ‘Add-AzureDataDisk’.
VERBOSE: Importing cmdlet ‘Add-AzureDisk’.
VERBOSE: Importing cmdlet ‘Add-AzureDjangoWebRole’.
VERBOSE: Importing cmdlet ‘Add-AzureEndpoint’.
VERBOSE: Importing cmdlet ‘Add-AzureEnvironment’.
VERBOSE: Importing cmdlet ‘Add-AzureNodeWebRole’.
VERBOSE: Importing cmdlet ‘Add-AzureNodeWorkerRole’.
VERBOSE: Importing cmdlet ‘Add-AzurePHPWebRole’.
VERBOSE: Importing cmdlet ‘Add-AzurePHPWorkerRole’.
VERBOSE: Importing cmdlet ‘Add-AzureProvisioningConfig’.
VERBOSE: Importing cmdlet ‘Add-AzureVhd’.
VERBOSE: Importing cmdlet ‘Add-AzureVMImage’.
VERBOSE: Importing cmdlet ‘Add-AzureWebRole’.
VERBOSE: Importing cmdlet ‘Add-AzureWorkerRole’.
VERBOSE: Importing cmdlet ‘Disable-AzureServiceProjectRemoteDesktop’.
VERBOSE: Importing cmdlet ‘Disable-AzureWebsiteApplicationDiagnostic’.
VERBOSE: Importing cmdlet ‘Enable-AzureMemcacheRole’.
VERBOSE: Importing cmdlet ‘Enable-AzureServiceProjectRemoteDesktop’.
VERBOSE: Importing cmdlet ‘Enable-AzureWebsiteApplicationDiagnostic’.
VERBOSE: Importing cmdlet ‘Export-AzureVM’.
VERBOSE: Importing cmdlet ‘Get-AzureAclConfig’.
VERBOSE: Importing cmdlet ‘Get-AzureAffinityGroup’.
VERBOSE: Importing cmdlet ‘Get-AzureCertificate’.
VERBOSE: Importing cmdlet ‘Get-AzureDataDisk’.
VERBOSE: Importing cmdlet ‘Get-AzureDeployment’.
VERBOSE: Importing cmdlet ‘Get-AzureDisk’.
VERBOSE: Importing cmdlet ‘Get-AzureDns’.
VERBOSE: Importing cmdlet ‘Get-AzureEndpoint’.
VERBOSE: Importing cmdlet ‘Get-AzureEnvironment’.
VERBOSE: Importing cmdlet ‘Get-AzureLocation’.
VERBOSE: Importing cmdlet ‘Get-AzureMediaServicesAccount’.
VERBOSE: Importing cmdlet ‘Get-AzureOSDisk’.
VERBOSE: Importing cmdlet ‘Get-AzureOSVersion’.
VERBOSE: Importing cmdlet ‘Get-AzurePublishSettingsFile’.
VERBOSE: Importing cmdlet ‘Get-AzureRemoteDesktopFile’.
VERBOSE: Importing cmdlet ‘Get-AzureRole’.
VERBOSE: Importing cmdlet ‘Get-AzureSBAuthorizationRule’.
VERBOSE: Importing cmdlet ‘Get-AzureSBLocation’.
VERBOSE: Importing cmdlet ‘Get-AzureSBNamespace’.
VERBOSE: Importing cmdlet ‘Get-AzureService’.
VERBOSE: Importing cmdlet ‘Get-AzureServiceDiagnosticsExtension’.
VERBOSE: Importing cmdlet ‘Get-AzureServiceProjectRoleRuntime’.
VERBOSE: Importing cmdlet ‘Get-AzureServiceRemoteDesktopExtension’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabase’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabaseImportExportStatus’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabaseServer’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabaseServerFirewallRule’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabaseServerQuota’.
VERBOSE: Importing cmdlet ‘Get-AzureSqlDatabaseServiceObjective’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageAccount’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageBlob’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageBlobContent’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageBlobCopyState’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageContainer’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageKey’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageQueue’.
VERBOSE: Importing cmdlet ‘Get-AzureStorageTable’.
VERBOSE: Importing cmdlet ‘Get-AzureStoreAddOn’.
VERBOSE: Importing cmdlet ‘Get-AzureSubnet’.
VERBOSE: Importing cmdlet ‘Get-AzureSubscription’.
VERBOSE: Importing cmdlet ‘Get-AzureVM’.
VERBOSE: Importing cmdlet ‘Get-AzureVMImage’.
VERBOSE: Importing cmdlet ‘Get-AzureVNetConfig’.
VERBOSE: Importing cmdlet ‘Get-AzureVNetConnection’.
VERBOSE: Importing cmdlet ‘Get-AzureVNetGateway’.
VERBOSE: Importing cmdlet ‘Get-AzureVNetGatewayKey’.
VERBOSE: Importing cmdlet ‘Get-AzureVNetSite’.
VERBOSE: Importing cmdlet ‘Get-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Get-AzureWebsiteDeployment’.
VERBOSE: Importing cmdlet ‘Get-AzureWebsiteLocation’.
VERBOSE: Importing cmdlet ‘Get-AzureWebsiteLog’.
VERBOSE: Importing cmdlet ‘Get-AzureWinRMUri’.
VERBOSE: Importing cmdlet ‘Import-AzurePublishSettingsFile’.
VERBOSE: Importing cmdlet ‘Import-AzureVM’.
VERBOSE: Importing cmdlet ‘Move-AzureDeployment’.
VERBOSE: Importing cmdlet ‘New-AzureAclConfig’.
VERBOSE: Importing cmdlet ‘New-AzureAffinityGroup’.
VERBOSE: Importing cmdlet ‘New-AzureCertificateSetting’.
VERBOSE: Importing cmdlet ‘New-AzureDeployment’.
VERBOSE: Importing cmdlet ‘New-AzureDns’.
VERBOSE: Importing cmdlet ‘New-AzureMediaServicesAccount’.
VERBOSE: Importing cmdlet ‘New-AzureMediaServicesKey’.
VERBOSE: Importing cmdlet ‘New-AzureQuickVM’.
VERBOSE: Importing cmdlet ‘New-AzureRoleTemplate’.
VERBOSE: Importing cmdlet ‘New-AzureSBAuthorizationRule’.
VERBOSE: Importing cmdlet ‘New-AzureSBNamespace’.
VERBOSE: Importing cmdlet ‘New-AzureService’.
VERBOSE: Importing cmdlet ‘New-AzureServiceDiagnosticsExtensionConfig’.
VERBOSE: Importing cmdlet ‘New-AzureServiceProject’.
VERBOSE: Importing cmdlet ‘New-AzureServiceRemoteDesktopExtensionConfig’.
VERBOSE: Importing cmdlet ‘New-AzureSqlDatabase’.
VERBOSE: Importing cmdlet ‘New-AzureSqlDatabaseServer’.
VERBOSE: Importing cmdlet ‘New-AzureSqlDatabaseServerContext’.
VERBOSE: Importing cmdlet ‘New-AzureSqlDatabaseServerFirewallRule’.
VERBOSE: Importing cmdlet ‘New-AzureSSHKey’.
VERBOSE: Importing cmdlet ‘New-AzureStorageAccount’.
VERBOSE: Importing cmdlet ‘New-AzureStorageContainer’.
VERBOSE: Importing cmdlet ‘New-AzureStorageContext’.
VERBOSE: Importing cmdlet ‘New-AzureStorageKey’.
VERBOSE: Importing cmdlet ‘New-AzureStorageQueue’.
VERBOSE: Importing cmdlet ‘New-AzureStorageTable’.
VERBOSE: Importing cmdlet ‘New-AzureStoreAddOn’.
VERBOSE: Importing cmdlet ‘New-AzureVM’.
VERBOSE: Importing cmdlet ‘New-AzureVMConfig’.
VERBOSE: Importing cmdlet ‘New-AzureVNetGateway’.
VERBOSE: Importing cmdlet ‘New-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Publish-AzureServiceProject’.
VERBOSE: Importing cmdlet ‘Remove-AzureAclConfig’.
VERBOSE: Importing cmdlet ‘Remove-AzureAffinityGroup’.
VERBOSE: Importing cmdlet ‘Remove-AzureCertificate’.
VERBOSE: Importing cmdlet ‘Remove-AzureDataDisk’.
VERBOSE: Importing cmdlet ‘Remove-AzureDeployment’.
VERBOSE: Importing cmdlet ‘Remove-AzureDisk’.
VERBOSE: Importing cmdlet ‘Remove-AzureEndpoint’.
VERBOSE: Importing cmdlet ‘Remove-AzureEnvironment’.
VERBOSE: Importing cmdlet ‘Remove-AzureMediaServicesAccount’.
VERBOSE: Importing cmdlet ‘Remove-AzureSBAuthorizationRule’.
VERBOSE: Importing cmdlet ‘Remove-AzureSBNamespace’.
VERBOSE: Importing cmdlet ‘Remove-AzureService’.
VERBOSE: Importing cmdlet ‘Remove-AzureServiceDiagnosticsExtension’.
VERBOSE: Importing cmdlet ‘Remove-AzureServiceRemoteDesktopExtension’.
VERBOSE: Importing cmdlet ‘Remove-AzureSqlDatabase’.
VERBOSE: Importing cmdlet ‘Remove-AzureSqlDatabaseServer’.
VERBOSE: Importing cmdlet ‘Remove-AzureSqlDatabaseServerFirewallRule’.
VERBOSE: Importing cmdlet ‘Remove-AzureStorageAccount’.
VERBOSE: Importing cmdlet ‘Remove-AzureStorageBlob’.
VERBOSE: Importing cmdlet ‘Remove-AzureStorageContainer’.
VERBOSE: Importing cmdlet ‘Remove-AzureStorageQueue’.
VERBOSE: Importing cmdlet ‘Remove-AzureStorageTable’.
VERBOSE: Importing cmdlet ‘Remove-AzureStoreAddOn’.
VERBOSE: Importing cmdlet ‘Remove-AzureSubscription’.
VERBOSE: Importing cmdlet ‘Remove-AzureVM’.
VERBOSE: Importing cmdlet ‘Remove-AzureVMImage’.
VERBOSE: Importing cmdlet ‘Remove-AzureVNetConfig’.
VERBOSE: Importing cmdlet ‘Remove-AzureVNetGateway’.
VERBOSE: Importing cmdlet ‘Remove-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Reset-AzureRoleInstance’.
VERBOSE: Importing cmdlet ‘Restart-AzureVM’.
VERBOSE: Importing cmdlet ‘Restart-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Restore-AzureWebsiteDeployment’.
VERBOSE: Importing cmdlet ‘Save-AzureServiceProjectPackage’.
VERBOSE: Importing cmdlet ‘Save-AzureVhd’.
VERBOSE: Importing cmdlet ‘Save-AzureVMImage’.
VERBOSE: Importing cmdlet ‘Save-AzureWebsiteLog’.
VERBOSE: Importing cmdlet ‘Select-AzureSubscription’.
VERBOSE: Importing cmdlet ‘Set-AzureAclConfig’.
VERBOSE: Importing cmdlet ‘Set-AzureAffinityGroup’.
VERBOSE: Importing cmdlet ‘Set-AzureAvailabilitySet’.
VERBOSE: Importing cmdlet ‘Set-AzureDataDisk’.
VERBOSE: Importing cmdlet ‘Set-AzureDeployment’.
VERBOSE: Importing cmdlet ‘Set-AzureEndpoint’.
VERBOSE: Importing cmdlet ‘Set-AzureEnvironment’.
VERBOSE: Importing cmdlet ‘Set-AzureLoadBalancedEndpoint’.
VERBOSE: Importing cmdlet ‘Set-AzureOSDisk’.
VERBOSE: Importing cmdlet ‘Set-AzureRole’.
VERBOSE: Importing cmdlet ‘Set-AzureSBAuthorizationRule’.
VERBOSE: Importing cmdlet ‘Set-AzureService’.
VERBOSE: Importing cmdlet ‘Set-AzureServiceDiagnosticsExtension’.
VERBOSE: Importing cmdlet ‘Set-AzureServiceProject’.
VERBOSE: Importing cmdlet ‘Set-AzureServiceProjectRole’.
VERBOSE: Importing cmdlet ‘Set-AzureServiceRemoteDesktopExtension’.
VERBOSE: Importing cmdlet ‘Set-AzureSqlDatabase’.
VERBOSE: Importing cmdlet ‘Set-AzureSqlDatabaseServer’.
VERBOSE: Importing cmdlet ‘Set-AzureSqlDatabaseServerFirewallRule’.
VERBOSE: Importing cmdlet ‘Set-AzureStorageAccount’.
VERBOSE: Importing cmdlet ‘Set-AzureStorageBlobContent’.
VERBOSE: Importing cmdlet ‘Set-AzureStorageContainerAcl’.
VERBOSE: Importing cmdlet ‘Set-AzureStoreAddOn’.
VERBOSE: Importing cmdlet ‘Set-AzureSubnet’.
VERBOSE: Importing cmdlet ‘Set-AzureSubscription’.
VERBOSE: Importing cmdlet ‘Set-AzureVMSize’.
VERBOSE: Importing cmdlet ‘Set-AzureVNetConfig’.
VERBOSE: Importing cmdlet ‘Set-AzureVNetGateway’.
VERBOSE: Importing cmdlet ‘Set-AzureWalkUpgradeDomain’.
VERBOSE: Importing cmdlet ‘Set-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Show-AzurePortal’.
VERBOSE: Importing cmdlet ‘Show-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Start-AzureEmulator’.
VERBOSE: Importing cmdlet ‘Start-AzureService’.
VERBOSE: Importing cmdlet ‘Start-AzureSqlDatabaseExport’.
VERBOSE: Importing cmdlet ‘Start-AzureSqlDatabaseImport’.
VERBOSE: Importing cmdlet ‘Start-AzureStorageBlobCopy’.
VERBOSE: Importing cmdlet ‘Start-AzureVM’.
VERBOSE: Importing cmdlet ‘Start-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Stop-AzureEmulator’.
VERBOSE: Importing cmdlet ‘Stop-AzureService’.
VERBOSE: Importing cmdlet ‘Stop-AzureStorageBlobCopy’.
VERBOSE: Importing cmdlet ‘Stop-AzureVM’.
VERBOSE: Importing cmdlet ‘Stop-AzureWebsite’.
VERBOSE: Importing cmdlet ‘Test-AzureName’.
VERBOSE: Importing cmdlet ‘Update-AzureDisk’.
VERBOSE: Importing cmdlet ‘Update-AzureVM’.
VERBOSE: Importing cmdlet ‘Update-AzureVMImage’.
PS C:\>

Teamcity Tip: Building all pull requests and updating the status to Github

I like to share a must-have tip for those who are using continuous integration/continuous delivery with github and teamcity.

Merging all pull requests and build all branches

Let’s talk about how we work with github. We keep the master as a stable branch and if we need to work on new feature or bug fixes, we create another branch and push it as a pull request once we’ve done the job. So, another guy can review the code and merge it to the stable branch. The challenge here is that we like to know whether there is any conflict or test failtures before we merge the code or not. Do we have to pull the latest, merge the code manually and run the tests to see the result? Would it be nice if your CI can tell you automatically after you’ve done your pull request?

if the answer is yes, here  is the solution for you. In the version control setting of your TeamCity project configuration, you can specify the branch specification. All you need to do  is adding two lines as below in “Branch specification” textbox and trigger the “run” button again.

Github - Merge all pull request and build them all

You will see the statuses of all branches (including merges) in your Teamcity dash board. pretty cool, huh? But of course, you will have to open your TeamCity home page to see the results. Would it be even nicer if you can see it on github itseft?

Github - Merge all pull request and build them all on TeamCity

Updating the commit status to Github

Github provides us the API for updating the commit status. Please refer to this official post “Commit Status API” for details.

status-001-20120830-161640

Don’t worry! You don’t have to worry about reading the spec or writing any code for it.  There is an awesome Teamcity plugin “TeamCity.GitHub” written Eugene Petrenko. You can download this plugin from his github repository and build it by yourself or you can just download it as zip file from TeamCity’s build artifact.

Step #1: And then put that zip file (No! don’t need to extract it) to <TeamCity Data Directory>/plugins. if you are not sure whether that folder is then you can check about it in your TeamCity Global setting page.

TeamCity - Global Setting

Step #2: Please restart the teamcity service

Step #3: Go to your team city project configuration => Build Steps. And click on “Add build feature” button. You will see the dialog below and select “Report change status to GitHub“.

Add Build Feature

Step #4: Fill up the required information such as user name, password, repository and etc. You can use the same URL that I mentioned in my screenshot unless you are using GitHub Enterprise.

Report change status to Github

Then, Good to go!

If your pull request is in good shape, you will see something like that at the bottom of your pull request in github.

your pull request is cool

Otherwise, you will get this. meaning you will have to do some manual works.

your pull request is bad for now

Ok. That’s all I know.. and that’s how we are using it.. If any feedback or comment, please shot.. Thanks!