Last active
October 6, 2022 16:21
-
-
Save ppanyukov/6aafc2031404a45bdbc815022a446eb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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