Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CLI in Git Bash

I am trying to use a bash (sh) script on windows to run a test deployment. I am running the script from the gitbash console so that I have a copy of bash, but doing so means that the azure clie is not available (i.e. azure command is not found). Does anyone know how I can get the Azure cli working in GitBash (I am assuming I just install it somewhere else) or should I change to a different way of using bash

like image 638
Pectus Excavatum Avatar asked Mar 23 '17 09:03

Pectus Excavatum


People also ask

How do I run Azure command-line?

For Windows, the Azure CLI is installed via a MSI, which gives you access to the CLI through the Windows Command Prompt (CMD) or PowerShell. When installing for Windows Subsystem for Linux (WSL), packages are available for your Linux distribution.

Does Azure have a CLI?

The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. The Azure CLI is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation.


2 Answers

Sometimes commands in windows git bash need .cmd appended. Also, another way of installing the Azure-Cli is through Chocolatey https://chocolatey.org/

Try this command after Azure-Cli is installed:

az.cmd --version 

Echoing mscrivo you can run the line below in CMD not PowerShell (elevated/admin)

echo "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} > "C:\Program Files\Git\mingw64\bin\az"  

Now you should be able to run in Git bash:

az --version 
like image 141
whindes Avatar answered Sep 21 '22 07:09

whindes


artberri noted the best solution in a comment:

Add the following to your %USERPROFILE%\.bashrc or %USERPROFILE%\.profile

alias az='az.cmd'

However, if you want to be able to use az in bash scripts, you'll need something a little more drastic, run the following from cmd prompt:

echo "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12} ${13} ${14} ${15} > "%SYSTEMROOT%\az"

That will essentially create a passthrough az command in your windows folder that can be run from anywhere and passes parameters through to az.cmd.

like image 38
mscrivo Avatar answered Sep 18 '22 07:09

mscrivo