Deploy your Azure Website with VSTS Build

4 minute read

From VSTS (Visual Studio Team Services) your can deploy to a Azure Website directly directly from a build. Setting this up will require a couple of steps. In this blog post I will help you trough these steps.

Create New Build

Navigate to VSTS within the browser and open the team page where a build definition needs to be added. From the team page select build to go to the build configuration section.

VSTS Team Page

The build tab will show the status of current builds. On this page you are also able to create a new build. To create a new build select the + icon in the upper left corner.

Create Build

Pressing the + icon will make a dialog appear. In this dialog you need to select what kind of build needs to be created. We want to deploy to Azure so we select the “Deployment”  tab and then select “Azure WebSite”.

New Build

When selected press next. On the next screen you have to specify a couple of build settings settings. For example the “Repository type” on this screen you can also select a check box called “continuous integration: build each check-in”. Selecting this option will make sure a new build will be queued after a check-in.

Build Settings

Select the configuration depending on you situation and click on “Create”. In the background the build definition will be created and you will be navigated to a screen that contains all the steps in order to deploy to Azure.

Configure the Build Definition Build Blocks

image

The first two building blocks of the build definition can stay as they are by default. In the first building block there is a setting called “MSBuild Arguments”. This settings shows for example were the Web Deployment Package will be placed:

/p:PackageLocation="$(build.artifactstagingdirectory)\\

The second block will execute tests if there are any in your solution. By default it will stop the build if there are tests that fail during the build. By selecting “Continue on error” the build will continue even if tests fail.

Test Building Block

The next block is the block that will execute the deployment. As you can see the block is red and that is because not all required properties are filled in.

Select the building block you will notice that the Azure subscription isn’t filled.

When starting with a new VSTS tenant you will not have any Azure subscriptions configured. The Azure Subscription can be configured by clicking on “Manage”.

Azure Deployment

Configure Azure Service Endpoint

Clicking on manage will open a new browser window will that brings you tot the services endpoint configuration page of VSTS. On this page a Azure Subscription needs to be added by selecting the + icon in the upper left corner, and then selecting Azure.

Add Azure Subscription

In the dialog that appears authentication information for windows Azure subscription needs to be filled in. This information has to be retrieved and this can be done with the Azure PowerShell window.

  • Open the Microsoft Azure PowerShell window in administrative mode
  • Execute the following PowerShell command:
Get-AzurePublishSettingsFile 
  • Executing the commend will open a web browser and automatically download your subscription file
  • Open the subscription file (named [SubscriptionName]-[Date]-credentials.publishsettings)
  • Find the Subscription ID and the ManagementCertificate in the file.

In the dialog window select “Certificate Based” and copy and past all the right information.

Azure Subscription

Press “OK” to save the Service Endpoint and navigate back to the build tab in your browser.

With the service endpoint configured the  Azure Subscription field needs to be refreshed. When the field is refreshed you can select the appropriate Azure Subscription.

After setting the Azure Subscription the Web Site information needs to be added. The Web Deploy Package settings will deploy all zip files within your build it is also possible to specific a specific package if your know the name by altering the line.

$(build.stagingDirectory)\MSFT-DEMO-WEBAPP.zip

image

The last two building block have the right configuration by default. If you want you can also delete them from the build definition.

Now that everything is setup correctly the build definition can be saved. When saving for the first time you will be able to give it a appropriate name.

image

When saved the build can be queued by selecting “Queue Build”.

image