az webapp new – Azure CLI extension to create and deploy a .NET Core or nodejs site in one command

Dev Tips

The Azure CLI 2.0 (Command line interface) is a clean little command line tool to query the Azure back-end APIs (which are JSON). It’s easy to install and cross-platform:

Once you got it installed, go “az login” and get authenticated. Also note that the most important switch (IMHO) is –output:

usage: az [-h] [--output {json,tsv,table,jsonc}] [--verbose] [--debug]

You can get json, tables (for humans), or tsv (tab separated values) for your awks and seds, and json (or the more condensed json-c).

A nice first command after “az login” is “az configure” which will walk you through a bunch of questions interactively to set up defaults.

Then I can “az noun verb” like “az webapp list” or “az vm list” and see things like this:

128→ C:Usersscott> az webapp list
Name Location State ResourceGroup DefaultHostName
------------------------ ---------------- ------- -------------------------- ------------------------------------------
Hanselminutes North Central US Running Default-Web-NorthCentralUS
HanselmanBandData North Central US Running Default-Web-NorthCentralUS
myEchoHub-WestEurope West Europe Running Default-Web-WestEurope
myEchoHub-SouthEastAsia Southeast Asia Stopped Default-Web-SoutheastAsia

The Azure CLI supports extensions (plugins) that you can easily add, and the Azure CLI team is experimenting with a few ideas that they are implementing as extensions. “az webapp new” is one of them so I thought I’d take a look. All of this is open source and on GitHub at and is discussed in the GitHub issues for azure-cli-extensions.

You can install the webapp extension with:

az extension add --name webapp

The new command “new” (I’m not sure about that name…maybe deploy? or createAndDeploy?) is basically:

az webapp new --name [app name] --location [optional Azure region name] --dryrun

Now, from a directory, I can make a little node/express app or a little .NET Core app (with “dotnet new razor” and “dotnet build”) then it’ll make a resource group, web app, and zip up the current folder and just deploy it. The idea being to “JUST DO IT.”

128→ C:Usersscottdesktopsomewebapp> az webapp new  --name somewebappforme
Resource group 'appsvc_rg_Windows_CentralUS' already exists.
App service plan 'appsvc_asp_Windows_CentralUS' already exists.
App 'somewebappforme' already exists
Updating app settings to enable build after deployment
Creating zip with contents of dir C:Usersscottdesktopsomewebapp ...
Deploying and building contents to app.This operation can take some time to finish...
All done. {
"location": "Central US",
"name": "somewebappforme",
"os": "Windows",
"resourcegroup": "appsvc_rg_Windows_CentralUS ",
"serverfarm": "appsvc_asp_Windows_CentralUS",
"sku": "FREE",
"src_path": "C:\Users\scott\desktop\somewebapp ",
"version_detected": "2.0",
"version_to_create": "dotnetcore|2.0"

I’d even like it to make up a name so I could maybe “az webapp up” or even just “az up.” For now it’ll make a Free site by default, so you can try it without worrying about paying. If you want to upgrade or change it, upgrade either with the az command or in the Azure portal. Also the site ends at up <name>!

DO NOTE that these extensions are living things, so you can update after installing with

az extension update --name webapp

like I just did!

Again, it’s super beta/alpha, but it’s an interesting experiment. Go discuss on their GitHub issues.

Sponsor: Get the latest JetBrains Rider for debugging third-party .NET code, Smart Step Into, more debugger improvements, C# Interactive, new project wizard, and formatting code in columns.

Source link

Leave a Reply