How to automatically deploy a Team Foundation Service + Git Project on Azure (Step by Step)

Motivation

Two weeks ago, Me and my partners, we decided to start a new project using Team Foundation Service with Git and host it on Azure. As usual, we start developing a full happy path from project creation until deployment, to test all the infrastructure involved. The TFS Account creation was OK, the Git repository was also OK, but when we tried to setup the build configuration to automatically publish our project after an automated build, we start to have some issues. We found this declaration on MSDN.

Deploying from TFS’s git repository to Windows Azure is not yet supported. It is on our radar tentatively mid of this year.
- Microsoft Employee

We can’t (until today) configure our Azure Website to deploy from a Git repository through Azure’s Portal. We end up, through the help of others blogs , configuring a trigger on team foundation service to publish our project after an successful commit. Community is all about share what we learn, so I decided to write a step by step tutorial that maybe can help someone with the same difficulties that we had or maybe we can receive more feedback and we improve even more our solution.



Tutorial

First of all, I will assume that you already have a Team Foundation Service Account and an Azure Account, if you don’t have yet, you can create them at TFS and at Azure.



1. Creating a Team Foundation Service + Git project.

1.1 – Logged in your TFS Account. Click in “New Team Project + Git” button.

tfs-account



1.2 – Fill up the form. Remember that you can’t rename this project in the future.

creating-project



1.3 – Click on “Navigate to project” and you will see your project info.

project-created



2. Creating a WebApp

2.1 – Click on “Open new instance of Visual Studio” to open an Visual Studio instance linked to your project.

open-new-instance



2.2 – Clone your git repository and choose your repository folder, remember the folder’s name cause after you will create your Web Application in this same folder.

clone-repo1


clone-repo-2



2.3 – Create a MVC 4 Web Application in your repository folder.

creating-app



2.4 – Commit it. Now we have a deployable project. The next step is to create our Azure WebSite.

commit-webapp



3 – Creating the Azure WebSite

3.1 – Logged in your Azure Portal, create a new azure website.

creating-web-site



3.2 – Download the publish profile.

download-publish-profile



4 – Configuring the automated deploy

4.1 – Import the publish profile that we downloaded. It will create a publish profile folder in our MVC project.

importing-publish-profile



4.2 – Configure a new build definition.

Go to Team Explorer -> Builds -> New Build Definition and create a new build definition.

team-explorer-new-build

On Trigger Tab, set the “Continuous Integration” radio, so the build will occur after each check in.

trigger-tab

On Source Settings Tab, select the managed branch.

source-settings

On Process Tab, fill the solution to build field with ‘MyApp.sln’.

Also fill the MsBuild arguments field with the following value:

/p:DeployOnBuild=true /p:PublishProfile=”pauloortinsblog – Web Deploy” /p:AllowUntrustedCertificate=true /p:UserName=$pauloortinsblog /p:Password=Re7ACb3g6By9idLoi6gsWGbdc8AK49HxqaEFNzxxxxxxxxxxxxxxx /p:VisualStudioVersion=11.0

You should get the UserName and the Password from the Publish Profile file.

publish-settings

process-tab



4.3 – Enable Build Services.

On your TFS Account -> Build Section, you need to add the build services to your account in the following section.

enable-build



5 – Testing the happy path

5.1 – Let’s make a change in one of our files, Index.cshtml.

change



5.2 – Committing the change and pushing it to the repository.

testing-happy-path



pushing



5.3 – A new build was queued on Team Foundation Service

build queued



5.4 – After the build the finished, the WebApp was deployed automatically.

website



Conclusion

This is it. I hope this post might help someone. You can also feel free to suggest an improvement in this process!

5 Comments

  1. Comment by Buck Hodges:

    Thanks for the very nice, detailed post! We will soon have a simpler approach available.

    In step 4.3, you shouldn’t have anything extra to do unless you explicitly wanted to enable the Windows 8.1 build pool.

  2. Comment by Mark:

    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.targets (4253): The value for PublishProfile is set to ‘”mobileservices1”’, expected to find the file at ‘C:\a\src\MobileWCF\Properties\PublishProfiles\”mobileservices1”.pubxml’ but it could not be found.

Leave a Reply

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