😀

Azure CLI を Git Bash で使う時の必須環境変数 MSYS_NO_PATHCONV

に公開

MSYS_NO_PATHCONV が無いとどうなるのか

az resource show \
  --ids $(az group show \
  --name test-rg \
  --query id \
  --output tsv)

例えばリソースグループの情報を取得するような例では、/subscriptions の前に C:/Program Files/Git が勝手に追加されてしまい Azure CLI が正常に動作しません。

bash
az resource: error: argument --ids: invalid ResourceId value: 'C:/Program Files/Git/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/test-rg'

これはスラッシュ / で始まる値をパスだと認識して自動的に Git Bash のパスを付加するデフォルトの仕様のようです。

MSYS_NO_PATHCONV=1 をつけて実行

bash
MSYS_NO_PATHCONV=1 az resource show \
  --ids $(az group show \
  --name test-rg \
  --query id \
  --output tsv)

下記のように正常に情報が取得できるようになりました。

bash
{
  "extendedLocation": null,
  "id": "/subscriptions/12345678-1234-1234-1234-123456789012/resourceGroups/test-rg",        
  "identity": null,
  "kind": null,
  "location": "japaneast",
  "managedBy": null,
  "name": "test-rg",
  "plan": null,
  "properties": {
    "provisioningState": "Succeeded"
  },
  "sku": null,
  "tags": {},
  "type": "Microsoft.Resources/resourceGroups"
}

毎回コマンドの前に入れるのが面倒なので私は、~/.profileexport MSYS_NO_PATHCONV=1 を設定しました。

参考

https://docs.microsoft.com/ja-jp/azure/developer/terraform/get-started-windows-bash?tabs=bash#create-a-service-principal

https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-auth-aci#authenticate-using-the-service-principal

Discussion