3

I am trying to set a tag named "GitBranch" on an Azure Resource Group:

Azure portal

When I call the command in PowerShell window -

az tag update --resource-id "/subscriptions/79ca5b...7f/resourceGroups/ccg-afarber2" --subscription "79ca5b...7f" --operation merge --tags GitBranch=Test

then it works:

PowerShell window

But when I try the same command in Git Bash window, then it fails.

I have also tried calling the following commands before and also tried both double and single quotes

az login
az account set --subscription "79ca5b....7f"

but the error is still the same:

ERROR: (MissingSubscription) The request did not have a subscription or a valid tenant level resource provider.

Git Bash window

And the reason why I am trying to get the command working in bash is because I get the same error for my Azure pipeline task:

  - task: AzureCLI@2
    displayName: 'Set Resource Group tag'
    inputs:
      azureSubscription: '${{ parameters.ArmConnection }}'
      scriptType: 'bash'
      scriptLocation: 'inlineScript'
      inlineScript: |
        az tag update \
          --resource-id '/subscriptions/${{ parameters.SubscriptionId }}/resourceGroups/${{ parameters.ResourceGroupName }}' \
          --subscription '${{ parameters.SubscriptionId }}' \
          --operation Merge --tags \
          GitBranch=$(git branch --show-current)

Azure pipeline error

What is happening here please?

On my PC I have azure-cli 2.28.0 installed.

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

1 Answers1

6

I have found a solution myself!

In a AzureCLI pipeline task, when you run an az cli command, which has parameters starting with a slash, then the MinGW bash will auto-append the current path.

To prevent this, you can prepend the following variable to the az command:

MSYS_NO_PATHCONV=1 az ....

A double slash works too:

Git bash window

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416