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
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With