Automated Publish From TFS To Azure

Image Source: TAKE A SWING

Hi, Today we will talk about Publishing from any Source Control to any Cloud Automatically. As a Microsoft MVP, I prefered TFS for Source Control and Azure as a Cloud :)

If you’ve ever been a bit interested in TDD or DDD, you must figure out the importance of automation. Why do we try to Automate everything? Because of saving time and making fewer mistakes. So let’s publish a website from the specific branch on TFS to Azure automatically.

We will create the AutoDeployTFS project as an Asp .Net Core Web App with .Net 5.0 framework.

When the project is created, you could see the default index page as below.

1-) Now let’s Create the Azure DevOps Project (https://dev.azure.com) for source repo (TFS). Firstly, if you didn’t create any organization before, create a new one as below.

2-) Secondly, create a project under the organization as below.

3-) Create an empty folder. Open Visual Studio 2019 and Connect to Azure DevOps. Enter the credentials.

4-) Connect to AutoDeploy project on TFS and Map&Get the empty folder.

5-) Now, move all the project files from the AutoDeploy to this empty folder. And “Commit All” files. And finally “Push”.

Your AutoDeploy project must be seen as below on TFS (Azure DevOps Project).

Now we created the AutoDeploy project on Visual Studio. We created AutoDeploy repo on TFS (Azure DevOps Project) and pushed the project to this Repo.
Now we need the server to publish this website. So let’s create WebSite on Azure. https://portal.azure.com/

Go to “Create Resource => Web App” and select it.

Now fill the necessary fields below in the form.

  • Name: Url address of the website.
  • Runtime stack: Working framework.
  • Region: Server Location.
  • App Service Plan: Server Hardware Configuration.

After creating the Website on Azure, now let’s connect it with TFS (Azure DevOps).

Select AutoDeploy => Deployment Center from the menu. In the below picture, we create a webhook from Azure Web Apps to TFS.

Source: You can select different kinds of sources(GitHub, BitBucket). For TFS, we select “Azure Repos”.

Now let’s setup the TFS connection configurations.

  • Source: Selected Repo source.
  • Organization: Select Azure Repos organization.
  • Project: Select WebApp project.
  • Repository: Select WebApp repository.
  • Branch: Select final branch. This is so important. This branch must come after Dev and Test branch. Everything must work properly. This brunch must be the final.

When someone pushes the final Web Application code to the “master” branch of “Azure DevOps”, it automatically publishes the Azure. So you don’t worry about the IIS publish for new updates anymore.

Conclusion:

In this article, we talked about Automation importance. DevOps is the most needed expertise these days. When we change and push the application to the specific branch, we don’t need the updated Azure Web Application because it will happen automatically. But we ignored the test for this scenario, and we can get live some broken pages accidentally on Azure. So firstly, we do not push the application directly to the master branch. And before pushing the brunch, we have to run some tests automatically. Maybe we can use some tools like Jenkins or TravisCI for running tests. And if everything is ok, we can push the source to the dev TFS brunch.

I hope this article helps you understand how to publish Azure automatically from the TFS and the importance of Automation. See you later until the next article or video. Bye.

“If you have read so far, first of all, thank you for your patience and support. I welcome all of you to my blog for more!”

I have been coding since 1993. I am computer and civil engineer. Microsoft MVP. Senior Software Architect. Ride motorcycle. Gamer. Have two daughters.