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 that means azure click is not available (i.e. azure command not found). Does anyone know how I can get Azure cli to work in GitBash (I assume I just installed it somewhere else), or I need to change another way of using bash

+23
source share
6 answers

Sometimes commands in windows git bash require the addition of .cmd. In addition, another way to install Azure-Cli is through Chocolatey https://chocolatey.org/

Try this command after installing Azure-Cli:

az.cmd --version 

By repeating mscrivo , you can run the line below in CMD and not in 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" 

You should now be able to work in Git bash:

 az --version 
+35
source

artberri noted the best solution in the comment:

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

alias az='az.cmd'

However, if you want to use az in your bash scripts, you need something more radical, run the following from the command line:

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"

In essence, this will create the passthrough az command in the Windows folder, which can be launched from anywhere and passed parameters to az.cmd.

+17
source

You need to install the CLI on your computer. There are several ways to do this.

I am a friend of NodeJS, so I use npm to install:

npm install -g azure-cli

More details here: https://www.npmjs.com/package/azure-cli

But you can do this in other ways. A very good way is to use docker. There are containers from Microsoft with a preinstalled version of Azure CLI.

 docker run -it --name azure microsoft/azure-cli 

On Windows 10 using ubuntu bash you can use:

 echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | \ sudo tee /etc/apt/sources.list.d/azure-cli.list sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893 sudo apt-get install apt-transport-https sudo apt-get update && sudo apt-get install azure-cli 

Or how a python enthusiast run

 pip install --user azure-cli 

Most importantly, the "az" / "az.bat" or "azure" bin is available through the path variable.

+3
source

In other words, Azure CLI for Windows is not compatible with Git Bash for Windows

https://github.com/Azure/azure-cli/issues/3445

+1
source

Do not use the MSI installer at all. Since the Azure command line interface is implemented in Python, use the Python installation method, as @blndev wrote. Thus, instead of az.cmd you get the az.bat shell az.bat and az , and the installation path will not contain spaces.

 pip install --user azure-cli 

More information about this method can be found at https://blogs.msdn.microsoft.com/brijrajsingh/2017/03/02/install-azure-cli-2-0-on-windows/

A symbolic link worked for me most of the time, but some commands still fail, for example

 az dls fs access set-entry ... 'C:\Program' is not recognized as an internal or external command, operable program or batch file 
0
source

I tried the @mscrivo solution. However, when you use the az command in a shell script, you still have problems due to spaces in the path. To do this, I created the azproxy.cmd file in% SYSTEMROOT% containing

 @echo off "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin\az.cmd" %* 

And then create a link to this file

 mklink "%SYSTEMROOT%\az" "SYSTEMROOT%\azproxy.cmd" 

PS the extended value% SYSTEMROOT% should not contain spaces, of course

-1
source

Source: https://habr.com/ru/post/1265818/


All Articles