Continuous deployment
.NET Core Azure Azure App Services CICD Continuous Deployment Continuous Integration DevOps Kudu MSBuild TeamCity Top

Deployment to an Azure App Service with Team City

Welcome to today’s post.

I will we discussing how to configure and publish a .NET Core web application that has been built and tested using the TeamCity CI build configuration into an existing cloud hosted Azure app service. 

In one of my previous, I discussed how to configure a basic build configuration using Team City CI to check out the source from GitHub repository, then build and run a set of unit tests.

In this post I will be expanding on that post by showing how to create an additional task that will publish a .NET Core application into Azure app services. The aim is to produce the following CI / CD flow:

Azure app service team city

The first requirement to construct an MSBuild command within our build configuration that will extract parameters from our publisher file (with extension pubxml) and with a few more additional parameters complete the task that will publish our web site into Azure.

First, we will construct a set of parameters below that will be used as our basis for the MSBuild command:

/p:PublishProfile="Properties\PublishProfiles\BookLoanWebApp - Web Deploy.pubxml"
/p:DeployOnBuild=True
/p:ProfileTransformWebConfigEnabled=False
/p:userName=%deployusername%
/p:password=%deploypwd%
/p:EnableMSDeployAppOffline=True
/p:verb=sync 
/p:dest=auto

The first parameter PublishProfile is the relative path to our Web deployment publisher file. It is relative to our Visual Studio project folder and the \work\[build id]\Properties\PublishProfiles sub-folder within the TeamCity buildAgent folder. From this file, MSBuild will obtain values such as the destination web site, user name, publishing method etc.

The DeployOnBuild parameter tells MSBuild after finishing publishing the web site to the Team City build publish output folder, then deploy the contents of the following folder to the destination web site:

The ProfileTransformWebConfigEnabled parameter tell MSBuild to transform the web.config before deployment to the web site. In cases where you may have a custom configuration for your site you can set this to False.

The next two parameters username and password are obtained from the build parameters we construct and configure as follows:

In the build steps configuration, click on the Add New Parameter button:

Enter a parameter for the user name:

You can make the parameter hidden so that is does not show up in deployment dialogs or in logs:

Do like wise for the deployment password:

You might be asking the question: Where do I get the credentials for these parameters?

The answer lies in the Azure portal App Services.

Open the Azure portal. Navigate to Application Services and the deployment center:

Select Deployment Credentials:

In the dialog that shows, copy the whichever part of the credential username / password and paste it into the corresponding Build Parameter configuration value.

The above parameters should be entered within the Command line parameters of the build task as shown:

After your build parameters are saved, they should look like this:

Save the build step.

Run the build agent.

After a while you will (if all steps are successful) see the deployment:

To confirm the deployment is successful, open the Azure Kudu console.

Navigate to the wwwroot folder and check the time stamp of the binPublish folder.

It will be close to the timestamps of the publish steps in the Team City build log. Confirm the agent build has succeeded:

The final check is to open the deployed Azure web site and confirm it has deployed successfully. The link will be:

https://[app name].azurewebsites.net

We have managed to successfully deploy a .NET Core application from a Team City CD pipeline into Azure App Services!

That’s all for today’s post.

I hope you have found it useful and informative.

In a future post I will look at the types of issues we may get during publishing from a Team City publish to an Azure web site and how to rectify them.

Social media & sharing icons powered by UltimatelySocial