Automating Code Deployment with Github and Azure – DEVELOPPARADISE
06/05/2018

Automating Code Deployment with Github and Azure

Today, we are going to learn how to deploy an ASP.NET Core application in Azure automatically from a Github repository.

Automating Code Deployment with Github and Azure

Requirements

  • Git installed + GitHub account
  • Visual Studio 2015 Update 4 or higher (DotNet Core installed)
  • Azure Subscription (create a free Azure account)

Creating an ASP.NET Core Application

Let’s create a simple ASP.NET Core app using Visual Studio so we can deploy it in Azure.

  1. Open Visual Studio and go to File -> New Project -> Visual C# -> Web, then choose ASP.NET Core application (.Net Core Framework).

    Automating Code Deployment with Github and Azure

  2. Choose the Web Application template.

    Automating Code Deployment with Github and Azure

  3. Let’s make some changes in Index.chtml file (Views/Home/Index.cshtml):

    Automating Code Deployment with Github and Azure

Uploading the Project to GitHub

Now let’s create a new GitHub repository to upload our project.

  1. Go to Github and create a new repository

    Automating Code Deployment with Github and Azure

  2. Open the command line and go to the project directory
  3. Type git init
  4. Then, git add . to add all the project files
  5. git commit -m "First commit"
  6. git remote add origin https://github.com/saibimajdi/GithubAzure.git (change it to your repository)
  7. git push -u origin master

Now our project has been uploaded to GitHub. You can refresh the repository page to check if the project has been uploaded successfully.

Creating Azure Web Application

Now we should create an Azure Web Application to host our project.

  1. Go to http://portal.azure.com and create a new Azure Web App.

    Automating Code Deployment with Github and Azure

  2. Now let’s give it a name and fill out the form and click the Create button.

    Automating Code Deployment with Github and Azure

  3. Wait until Azure completes the creation of our application.
  4. Go to Deployment Options.

    Automating Code Deployment with Github and Azure

  5. Choose Github as a source, you can choose any other source such as One Drive, Dropbox or Bitbucket.

    Automating Code Deployment with Github and Azure

  6. Authorize Azure to use your Github account by entering your Github account credentials.

    Automating Code Deployment with Github and Azure

  7. Choose the project repository

    Automating Code Deployment with Github and Azure

  8. Choose the branch, in this case, we have only one branch (master):

    Automating Code Deployment with Github and Azure

  9. Now Azure is building your project to deploy it.

    Automating Code Deployment with Github and Azure

  10. Automating Code Deployment with Github and Azure

Voilà, our application has been deployed in Azure automatically from our Github repository, every time we make new commit to our repository, Azure will take the latest version from the master branch and deploy it.

Automating Code Deployment with Github and Azure

Check out the video to understand more about automating code deployment with Github and Azure.

That’s all for this article! I wish that you have learned something new. Feel free to contact me if there are any questions.