Written by

Ravishankar

Share

  

Category

see all categories
intranet as a service

How To Create A Web App With Deployment From GitHub Using Azure 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 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  

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 centre location of the resource group, such as southindia and westus 

$ResourceGroupName="HubflyGroup003" 

$location="southindia" 

New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location 

ResourceGroupName

Now check your azure portal the resource group will be created  

resource group

Creating App Service Plan 

Create a 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 centre location of the resource group, such as southindia and westus 

$webappname="Hubflysoft" 

New-AzureRmAppServicePlan -Name $webappname -Location $location  ResourceGroupName $ResourceGroupName -Tier Free 

Azure data centre location

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 

New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $ResourceGroupName 

Azure data centre

Configuring the GitHub with Azure Web App: 

Create a github configuration using  PowerShell splatting  to pass as parameter to the azure cmdlets. 

$gitrepo="https://github.com/ravishankar1730/Azure-PHP.git" 

$PropertiesObject = @{ 

    repoUrl = "$gitrepo"; 

    branch = "master"; 

    isManualIntegration = "true"; 

} 

isManualIntegration

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. 

 Set-AzureRmResource  -PropertyObject $PropertiesObject  -ResourceGroupName

$ResourceGroupName  -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName

 $webappname/web -ApiVersion 2015-08-01  -Force 

AzureRmResource

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

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

Full source code: 

Connect-AzureRmAccount  

# Replace the following URL with a public GitHub repo URL 

$gitrepo="https://github.com/ravishankar1730/Azure-PHP.git" 

$webappname="Hubflysoft" 

$location="southindia" 

$ResourceGroupName="HubflyGroup002" 

# Create a resource group. 

New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location 

# Create an App Service plan in Free tier. 

New-AzureRmAppServicePlan -Name $webappname -Location $location -ResourceGroupName $ResourceGroupName -Tier Free 

# Create a web app. 

New-AzureRmWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $ResourceGroupName 

# Configure GitHub deployment from your GitHub repo and deploy once. 

$PropertiesObject = @{ 

    repoUrl = "$gitrepo"; 

    branch = "master"; 

    isManualIntegration = "true"; 

} 

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 

Azure Portal