In Focus

How To Create A Web App With Deployment From GitHub Using Azure PowerShell

This is a step by step article on creating a web app with deployment from GitHub using Azure PowerShell. Create, deploy and test web apps using Azure and PowerShell

In this article, we are going to see the steps required to create a Web App with deployment from GitHub using Azure PowerShell. You can create, deploy and test web apps using Azure PowerShell. Azure PowerShell contains sets of modules that provide multiple cmdlets to manage Azure with Windows PowerShell.

Prerequisite

Before you begin to utilize PowerShell to oversee the Azure PowerShell, ensure that the Azure PowerShell has been installed. If not installed, here is an article on How to install the Azure PowerShell module. You need to do this only once for each computer from which you are running Azure PowerShell commands.

Connecting to Azure Portal

Connect to Azure Portal using Connect-AzureRmAccount cmdlet.

Connect-AzureRmAccount

Connecting to Azure Portal

Creating Azure Resource Group
 
Create an Azure Resource Group so that we can deploy, update, and test web apps in a group. Azure Resource Group is a new approach to group a collection of resources that share a unified life cycle. The benefit of using resource groups in Azure is that we can group all resources that belong to one application.

You can create Resource Groups in Azure using New-AzureRmResourceGroup cmdlets. The required parameters are,
  • Name - Specify the name of the resource group.
  • Location - Specify the Azure data center location of the resource group, such as southindia and westus.
    1. $ResourceGroupName="HubflyGroup003"  
    2. $location="southindia"  
    3. New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location   
Creating Azure Resource Group

Now check your Azure portal the resource group will be created
 
resource group

Creating App Service Plan
 
Create an App Service plan using New-AzureRmAppServicePlan cmdlets for the resource group. The required parameters are,
  • Name - Specify the name of the webApp.
  • ResourceGroupName - Specify the name of the resource group
  • Location - Specify the Azure data center location of the resource group, such as South India and the West US.
    1. $webappname="Hubflysoft"  
    2. New-AzureRmAppServicePlan -Name $webappname -Location $location ResourceGroupName $ResourceGroupName -Tier Free  
Creating App Service Plan

Creating Azure Web App
 
Create a web app using New-AzureRmWebApp cmdlets. The required parameters are,
  • Name - Specify the name of the webApp.
  • ResourceGroupName - Specify the name of the resource group
  • Location - Specify the Azure data centre location of the resource group, such as southindia and westus.
    1. New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $ResourceGroupName  

Creating Azure Web App

Configuring the GitHub with Azure Web App

Create a GitHub configuration using PowerShell splatting to pass as a parameter to the Azure cmdlets.
  1. $gitrepo="https://github.com/ravishankar1730/Azure-PHP.git"  
  2. $PropertiesObject = @{  
  3.    repoUrl = "$gitrepo";  
  4.    branch = "master";  
  5.    isManualIntegration = "true";  
  6. }  
GitHub with Azure Web App

Now, modify the existing Azure resource using Set-AzureRmResource cmdlets. The required parameters are -
  • PropertyObject - Specify the GitHub config we have already created using PowerShell splatting
  • ResourceGroupName - Specify the name of the resource group.
  • ResourceType - Specify the type of the resource.
  • ResourceName - Specify the name of the web app.
  • ApiVersion - Specify the name of the Web API version.
    1. Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force  
required parameters

Now, you can check the web app configured with GitHub like below snapshot.
 
web app configured with github

Open the web app URL in your browser and check whether the GitHub source has been deployed to the web app that we have created.
 
web app URL

Full source code
  1. Connect-AzureRmAccount  
  2. # Replace the following URL with a public GitHub repo URL  
  3. $gitrepo="https://github.com/ravishankar1730/Azure-PHP.git"  
  4. $webappname="Hubflysoft"  
  5. $location="southindia"  
  6. $ResourceGroupName="HubflyGroup002"  
  7. # Create a resource group.  
  8. New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location  
  9. # Create an App Service plan in Free tier.  
  10. New-AzureRmAppServicePlan -Name $webappname -Location $location -ResourceGroupName $ResourceGroupName -Tier Free  
  11. # Create a web app.  
  12. New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $ResourceGroupName  
  13. # Configure GitHub deployment from your GitHub repo and deploy once.  
  14. $PropertiesObject = @{  
  15.    repoUrl = "$gitrepo";  
  16.    branch = "master";  
  17.    isManualIntegration = "true";  
  18. }  
  19. Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force  
I hope you have learned to create a Web App with deployment from GitHub using Azure PowerShell programmatically. Feel free to fill up the comment box below if you need any assistance.