To make it clear: This is not about Git tags. I'm talking about the tags one can add to individual pipeline builds. For example when using the logging command ##vso[build.addbuildtag].
The build pipeline adds a number of tags to its builds. For example the release number, whether the build is for a release candidate, etc...
My question is how I can get these tags in a release pipeline based on the tagged pipeline build.
[EDIT] The solution applied
The way I implement is in a Command task, using Bash. The only dependency is a (secret) variable named "myvars.pat". Which is the personal access token created for this particular case. I've used a variable group for sharing the token with different release pipelines.
# Construct the url based on the environment
ORG=$(basename $(System.CollectionUri))
URL=https://dev.azure.com/$ORG/$(Build.ProjectName)/_apis/build/builds/$(Build.BuildId)/tags?api-version=5.1
# Base64 the PAT token. Mind the ':' prefix !
PAT=$(echo -n ":$(myvars.pat)" | base64)
# Make the GET request. "-L" is needed to follow redirects.
curl -L -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic $PAT" -s -o ./tags.json $URL
# Using default tools to extract the array. No doubt there is a cleaner way.
tags=$(cat ./tags.json | cut -d "[" -f 2 | cut -d "]" -f 1 | tr -d '"' | tr ',' ' ')
# There are the tags
for tag in $tags; do
echo $tag
done
# Set them as a variable to be used by the subsequent tasks
echo "##vso[task.setvariable variable=Build.Tags;]$tags"
# Clean up
rm ./tags.json