{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/azure-cli-show-query-output-properties",
  "description": "Discover how to query Azure deployment outputs using the Azure CLI, bash, and jq, and convert them to GitHub Action job outputs.",
  "path": "/posts/azure-cli-show-query-output-properties",
  "publishedAt": "2021-12-28T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "github actions",
    "azure"
  ],
  "textContent": "It's often desirable to query the outputs of deployments to Azure. This post demonstrates how to do this using the Azure CLI, bash and jq. It also shows how to generically convert deployment outputs to GitHub Action job outputs.\n\n\n\nDeployment outputs\n\nWhen we deploy something to Azure, we frequently have outputs which we want to use. Let's consider the canonical case, whereby a website is created and we want to use the URL of where it has been deployed. We can see these values in the Azure Portal:\n\nThe above deployment has a single output of nodeUrl. Rather than logging into the portal to acquire this value, how can we do so using the Azure CLI and bash?\n\nAcquire all outputs\n\nThe way to acquire outputs from the Azure CLI is using the az group deployment show command:\n\nRunning the above will produce a piece of JSON that contains all our outputs. In our case, we have a single deployment output: nodeUrl. So our JSON looks like this:\n\nAcquire an individual output\n\nTo acquire an individual output, you can provide a targeted --query to pull out the value you care about. However, there's a slight issue:\n\nThe value we capture in the NODE_URL variable above is surrounded by quotes. These will probably get in the way when we're scripting something with this. Rather than purging them with bash, I tend to use jq's --raw-output / -r option to grab the raw string.\n\nPerfect!\n\nThere's another approach you could use which Aleksandar Nikolić shared, which means jq needn't be used at all; using the tsv output formatter:\n\nConvert deployment outputs to GitHub Action job outputs\n\nBefore wrapping up, here's one more useful script, if you find yourself automating in the context of GitHub Actions. It's often useful to take the deployment outputs, and convert them into GHA job outputs that can be used in other jobs.\n\nWith JSON and jq in hand, it's possible to expose these like so:",
  "title": "Query deployment outputs with the Azure CLI"
}