I am trying to run an Azure DevOps Task with nested az cli command. I have defined the variables at the beginning of the azure-pipelines.yaml
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
resourceGroup: test1234
acrName: taerarawrr2.azurecr.io
Within tasks I can access the values by using $(resourceGroup) and $(acrName). Now I want to run an az cli task which uses these two variables, and saves the output of the command in a new variable (ACR_LOGIN_SERVER), which can be later used in the task.
- task: AzureCLI@2
displayName: Run docker image
inputs:
azureSubscription: serviceprincipaltest
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
$ACR_LOGIN_SERVER= $(az acr show --name $(acrName) --resource-group $(resourceGroup) --query "loginServer" --output tsv)
echo $(ACR_LOGIN_SERVER)
This however fails for some reason. I guess there is something wrong with the syntax of this nested command. I've tried using parentheses, $ and quotation marks in various locations but nothing seems to work. I also didn't manage to find any example how such an inline script should be formatted correctly. Any help would be greatly appreciated.