How to deploy azure app service with azure cli from local git

2 months ago

This tutorial is additon to the ms azure tutorial
Install azure cli
Login to azure

az login

it will open brower for you to login.
After login.
Check your current subscription
Your active subscription is marked as True in the IsDefault column.

az account list -o table
Name                  CloudName    SubscriptionId                        State    IsDefault
--------------------  -----------  ------------------------------------  -------  -----------
Azure subscription 1  AzureCloud   id1                                   Enabled  True
Azure subscription 2  AzureCloud   id2                                   Enabled  False

As you can see you currently in Azure subscription 1 to change subscription

 az account set --subscription subscription 2

You dont need to type the whole subscription name. Just type G and tab
Now check again

az account list -o table
Name                  CloudName    SubscriptionId                        State    IsDefault
--------------------  -----------  ------------------------------------  -------  -----------
Azure subscription 1  AzureCloud   id1                                   Enabled  False
Azure subscription 2  AzureCloud   id2                                   Enabled  True

Now you are in the right subscription.
Check list app app service

az webapp list

If you got error

To fix that you need to insetall decorator

 pip install decorator
# output
Collecting decorator
  Downloading decorator-5.0.9-py3-none-any.whl (8.9 kB)
Installing collected packages: decorator
Successfully installed decorator-5.0.9

Create deployment git local

Option 1:

az webapp deployment source config-local-git --resource-group proj1 --name vt1test
# output
  "url": ""

Option 2: Azure portal

It will show you the git url after

Connect local to app service git

# git uri Format

git remote set-url origin

Test git remote

git remote -v
# output
origin (fetch)
origin (push)

Test git pus

git push
fatal: Authentication failed for ''

You will get an Authentication failed error
To fix that:

Deployment center

Now go to app service -> deployment center -> Local Git/FPTS credentials

Scroll down to user scope and set new username and password

Option 1: check your local git credential username

git config --list
credential.username=vt1test # copy this username and paste in the username above

Option 2: Set username in portal then update your local username.
Set username and password. Example username: vt1test password: your_password
Now update your local username

git config --global --edit
# Out put

        name = VUONGT1
        email =
        username = Vuong
        username = vt1test # here is your username

Check git push again it will work

git push
Enumerating objects: 75, done.
Counting objects: 100% (75/75), done.
Delta compression using up to 8 threads
Compressing objects: 100% (71/71), done.

Now check your app url for the update.

To update you can just change your local branch then git push comment again.


How to update new code from source control?

git pull


git remote add something git://
git checkout master
git pull something master