Close

Deploy Azure App Service via Azure CLI

Azure CLI (or Bash) is a cross-platform command-line interface with commands to create and manage Azure resources. It’s an easy-to-use to use, cross-platform alternative for Powershell.
Further reading: docs.microsoft.com

For me, the reason to look at Azure CLI, was an upgrade of Powershell. The deployment scripts I was using no longer worked, so I either had to rewrite my Powershell scripts or move to Bash. I chose the latter. One further note. I started working for the client in 2016. That’s the reason why we don’t use Azure DevOps and YAML pipelines. Those technologies were not mature at the time. Moreover, Azure DevOps pipelines are not exactly easy to use.

Anyhow. Here is the script to deploy an Azure App Service. Note that I manually create a deployment package (*.zip) in Visual Studio first. Also, we don’t use service principals, which would be an obvious improvement. Less relevant by the way, since we run the deployment scripts by hand and not unattended. Suboptimal indeed, I know.

#!/bin/bash

if [ “$1” == “Dev” ]; then
AppServiceName=DevService
ResourceGroup=appservices-dev
ZipFile=Service.zip
ParameterFile=@ParametersDev.json
echo “Start Deploy $AppServiceName”
fi

az login -u <username> -p <password>

# AppService Deploy
az webapp deployment source config-zip –resource-group $ResourceGroup –name $AppServiceName –src $ZipFile

# Add ApplicationSettings
az webapp config appsettings set -g $ResourceGroup -n $AppServiceName –settings $ParameterFile

We cannot run bash scripts from the command line just like that. I used Visual Studio Code, but I’m sure there are alternatives.

  • Open Visual Studio Code
  • Select Bash as the default Shell
    Menu View / Command Pallette / Terminal: Select Default Shell / Git Bash
  • If the Terminal Window is not open yet:
    View / Terminal
  • Run Command from Terminal window (wait for prompt, may take a while):
    Bash DeployDevService.sh Dev (after change directory/cd)