Skip to content

Instantly share code, notes, and snippets.

@ppanyukov
Last active October 6, 2022 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppanyukov/6aafc2031404a45bdbc815022a446eb8 to your computer and use it in GitHub Desktop.
Save ppanyukov/6aafc2031404a45bdbc815022a446eb8 to your computer and use it in GitHub Desktop.
# Shows how to get auth token for VSTS (Azure Devops) from Azure CLI.
#
# Extracted from various github projects: Azure CLI and Azure SDK for Go
# See: https://github.com/Azure/azure-sdk-for-go/blob/ca5ebc8601ba1af17b289bb42161b7afb496423f/eng/common/scripts/Helpers/DevOps-WorkItem-Helpers.ps1#L17
# VSTS / Azure Devops resource identifier is: "499b84ac-1321-427f-aa17-267ca6975798"
organisation="your_org"
project="your_project"
# Using curl
VSTS_TOKEN=$(az account get-access-token --resource "499b84ac-1321-427f-aa17-267ca6975798" --query "accessToken" --output tsv)
curl -i -H "Authorization: Bearer ${VSTS_TOKEN}" "https://dev.azure.com/${organization}/${project}/_apis/build/definitions?api-version=7.1-preview.7"
# Anecdotal evidence suggests that gettis a default token from Azure CLI
# also works now. I'm sure it didn't work before.
VSTS_TOKEN=$(az account get-access-token --query "accessToken" --output tsv)
curl -i -H "Authorization: Bearer ${VSTS_TOKEN}" "https://dev.azure.com/${organization}/${project}/_apis/build/definitions?api-version=7.1-preview.7"
# Using Azure Cli rest. For this you still need to supply the resource identifier.
az rest --resource "499b84ac-1321-427f-aa17-267ca6975798" --url "https://dev.azure.com/${organization}/${project}/_apis/build/definitions?api-version=7.1-preview.7"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment