Setting Up CI And CD For Azure App Services With Github And Azure CLI 2.0

We are going to deploy a GitHub repo to Azure App Service and configure CI/CD for that repo through the Azure CLI 2.0 so if you’re not aware of the Azure CLI 2.0, I will request you to go to my previous blog posts here and here.

First, we will list down all the steps required for it. The steps are as follows:

Create a Resource Group

We will create a resource group with the name githubdemorg and host it in location EASTUS

az group create –name githubdemoorg –location EASTUS

Azure

Create an App Service Plan

An App Service Plan is to define the size, location, scale count, and sku of the app where you will be hosting it.

az appservice plan create –name githubdemplan –resource-group githubdemoorg –sku FREE

Azure

Create a Web App

We will create a new web app with the following command.

az appservice web create –name githubdemoag –resource-group githubdemorg –plan githubdemoplan

Azure

Create a Git repo in Github

If you’re not familiar with github, just follow the steps.

  • Go to Github.com and Signup/login with your Credentials
  • Click on Start a project

    Azure

  • Create a new repository by passing a repo name and description and make your Repo as public. Also, make sure that you didn’t check the Initialize this repository with a README if you’re not familiar with github and blindly follow this demo.

    Azure
Push the Code to the Github

Go to your code directory and open a new instance of the command prompt for the git command and follow the new or existing repository on the command line according to the requirement.

For us, we did the new repository in the demo. Let me quickly walk through the commands.

git init

It’s going to initiate a new blank repository in your local

git add readme.md

It is going to add a readme file to the repo.

git commit –m “first commit”

It is going to commit the code with the message in the double quote

git remote add origin url

It’s going to add the remote to the origin.

git push –u origin master

It’s going to push to origin git repo in the master branch

Azure

Once you completed the above commands then go to your repo on github and check if the files got pushed.

Azure

Deploy Code from a public Github Repository with CI &CD

In order to set up the source control config, you need to authenticate your command line with a token, and in order to get the token you need to go to github.com and then settings and on bottom left click on personal access token.

Azure

Click on "Generate new token" and enter the token description.

Azure

Click on "Generate token" button at the bottom.
Azure
Copy the token generated in this step and use it in the next step. I have not used it in the screenshot below as I have already set up the token once and Azure remembers the token.

az appservice web source-control config –name githubdemoag –resource-group githubdemorg –repo-url YOURREPOURL –branch master --git-token $token

Azure

Azure

Validate CI & CD

Now, to validate the CI CD Configuration, I am going to make a simple code change in my HTML and append Updated to GITHUB DEMO and I am going to push the code to git hub and check the site again to see if the changes are reflecting or not.

Update the HTML File

Azure

Push the code to the github by using the following commands in your git cmd

Git add .

Git commit –m “new commit”

Git push

Azure

Check the site again.

Azure


Similar Articles