0

I've been trying to store the output of multiple az cli commands in a variable defined in my pipeline with 0 success.

This being my last attempt: enter image description here

The way I try to make sure is getting pass to the var is by doing an echo, which it outputs this(in all attempts): enter image description here

At the end what im trying to achieve is to get the key value stored to use later: enter image description here

Any suggestions on how to do this in the Azure CLI task from Azure DevOps Pipeline?

PS: Have being trying some commands from shell and batch and must of the attempts failures are related to not recognizing commands(batch/shell) inside the script. Which is confusing since in Azure cli task Docs:

enter image description here

Answer

@4c74356b41 Answer helped a lot since I didn't know I could do query in azure cli commands to get a specific value of a command. But it didn't quite answer my questions. All that said, this link Set Output Variable in Azure CLI task on VSTS has the Answer to my question.

BAcevedo
  • 105
  • 3
  • 12

1 Answers1

2

just use query path filtering, something like this:

--query 'properties.properties.sites[0].key' -o tsv

this should output only the key you are interested it. reading:

https://learn.microsoft.com/en-us/cli/azure/query-azure-cli?view=azure-cli-latest

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • This was of much help, thanks. Help me narrow down to just that variable and not loop trough a json obj. Still I need to store it in a variable inside the azure cli task from azure DevOps any ideas on how to do this? I declared the variable but not able to assign it with "=". $var="$(az cli --query 'temp.temp.sites[0]....) – BAcevedo Feb 15 '19 at 15:58
  • you can use save the output to variable feature, but I, sadly, never really used that, so I dont know how it works exactly, its the last option of the task step – 4c74356b41 Feb 15 '19 at 15:59