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 TeamCity

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 TeamCity CI to check out the source from GitHub repository, then build and run a set of unit tests.

I will be expanding on my previous post by showing how to create an additional task that will publish a .NET Core web application into Azure App Services.

In our continuous integration and continuous deployment pipeline, the task that deploys our application into the cloud environment is the final task in the release pipeline. The continuous integration part of our pipeline is triggered following a commit from our code versioning environment (in this case, a GitHub repository).

The committed code is then built to ensure that it does not contain syntactic errors and produces a clean set of artifacts that include scripts, content, markup, and binaries. Then the code is unit tested through another build integration task that executes a run of the unit test project. Once the tests have been passed successfully, we then kick off the web deployment publish task that is configured with Azure App Service and Web Site environment configurations.

The resulting end-to-end process that defines the pipeline is depicted in the following CI / CD flow that we will implement:

Azure app service team city

Configuration of MSBuild to Build and Publish to the Deployment Output Folder

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 TeamCity 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:

In the next section I will be showing how to determine the deployment credentials for your release pipeline tasks.

Determining Deployment Credentials

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 displays in the Azure App Service Deployment Credentials, copy the each 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 will resemble the following configuration parameters:

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 TeamCity 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 TeamCity 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 TeamCity publish to an Azure web site and how to rectify them.

Social media & sharing icons powered by UltimatelySocial