'az acr command working fine in bash run but not in pipeline

I am running below command from bash command line (Ubuntu subsystem)

az acr import --username AAAA --password AAAA --name AAAA --source "AAAA/AAAA:AAA" --image "AAAA:AAA" 

If I use the same in Azure pipeline but getting below error

ERROR: Please run 'az login' to setup account.

Any suggestions?



Solution 1:[1]

Unlike manually executing the Azure CLI commands locally, in Azure Pipelines, you need to use the specific Azure CLI task to execute the Azure CLI commands.

Below are the things you need to do:

  1. Create an Azure Resource Manager service connection (ARM connection) that can connect to the Azure subscription and Source Group where the ACR are in.
  2. In the pipeline, add the Azure CLI task.
    • Select the ARM connection created in previous step as the value of Azure Resource Manager connection field. The task will use the ARM connection as the authentication to access the ACR.

    • Select Shell as the value of Script Type field.

    • Add Azure CLI commands as the Inline Script on the task.

      If the source registry is ACR, you can try with the following command.

      az acr import --name AAAA --source "AAAA/AAAA:AAA" --image "AAAA:AAA" 
      

      If the source registry is outside Azure, you can try with the following command.

      az acr import --username AAAA --password AAAA --name AAAA --source "AAAA/AAAA:AAA" --image "AAAA:AAA" 
      

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bright Ran-MSFT