0

How do scan the output from the Azure Cli to extract the child iteration name or child iteration path --Azure Devops/Bash/AzureCLI

My idea is to scan the output for the specific iteration name.

it will list all the iteration under the depth 3 in your organization with output $Scanoutput=az boards iteration project list

it has the child iteration name: ABC in the iteration project list

So how can you scan this output and Extract the iteration Name by search something like $Scanoutput.ABC.IterationPath So that I can get the child iteration path Thanks

12345GG
  • 101
  • 8
  • 2
    Do you mean **parse** the output to extract a value? use the command line option **--query** or a CLI tool such as **jq**. Edit your question and include the command you are running and the output. Then explain clearly which part of the output you need to extract. – John Hanley Oct 01 '21 at 23:35
  • Have you had a chance to check the provided solution? – Bhargavi Annadevara Oct 08 '21 at 03:56

1 Answers1

0

You can always use the --query argument to execute a JMESPath query on the results of az commands.

Considering the following sample output for az boards iteration project list:

{
  "attributes": null,
  "children": [
    {
      "attributes": {
        "finishDate": "2020-11-30T00:00:00Z",
        "startDate": "2020-11-01T00:00:00Z"
      },
      "children": null,
      "hasChildren": false,
      "id": 9,
      "identifier": "874d453a-q2e3-48a2-ac2f-3f6d316ec038",
      "name": "Iteration 1",
      "path": "\\sandbox\\Iteration\\Iteration 1",
      "structureType": "iteration",
      "url": "https://dev.azure.com/sandbox/1b4737br-4035-4ce7-bcb8-7df9a2df3585/_apis/wit/classificationNodes/Iterations/Iteration%201"
    },
    {
      "attributes": {
        "finishDate": "2020-12-31T00:00:00Z",
        "startDate": "2020-12-01T00:00:00Z"
      },
      "children": null,
      "hasChildren": false,
      "id": 10,
      "identifier": "a7f661a2-78bb-4317-afbb-c6015d2a4da5",
      "name": "Iteration 2",
      "path": "\\sandbox\\Iteration\\Iteration 2",
      "structureType": "iteration",
      "url": "https://dev.azure.com/sandbox/1b4737br-4035-4ce7-bcb8-7df9a2df3585/_apis/wit/classificationNodes/Iterations/Iteration%202"
    },
    {
      "attributes": null,
      "children": null,
      "hasChildren": false,
      "id": 11,
      "identifier": "302ffcee-9250-89g2-a323-3dba5f107738",
      "name": "Iteration 3",
      "path": "\\sandbox\\Iteration\\Iteration 3",
      "structureType": "iteration",
      "url": "https://dev.azure.com/sandbox/1b4737br-4035-4ce7-bcb8-7df9a2df3585/_apis/wit/classificationNodes/Iterations/Iteration%203"
    }
  ],
  "hasChildren": true,
  "id": 7,
  "identifier": "4543c1f2-98e4-4379-9323-177837fd0467",
  "name": "sandbox",
  "path": "\\sandbox\\Iteration",
  "structureType": "iteration",
  "url": "https://dev.azure.com/sandbox/1b4737br-4035-4ce7-bcb8-7df9a2df3585/_apis/wit/classificationNodes/Iterations"
}

You can use a query expression like:

az boards iteration project list --query 'children[].{Name:name,IterationPath:path}'

to get the name and iteration path of children:

[
  {
    "IterationPath": "\\sandbox\\Iteration\\Iteration 1",
    "Name": "Iteration 1"
  },
  {
    "IterationPath": "\\sandbox\\Iteration\\Iteration 2",
    "Name": "Iteration 2"
  },
  {
    "IterationPath": "\\sandbox\\Iteration\\Iteration 3",
    "Name": "Iteration 3"
  }
]
Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30