澄清一下:这与Git 标签无关。我正在谈论可以添加到单个管道构建中的标签。例如,当使用日志记录命令##vso[build.addbuildtag]时。
构建管道向其构建添加了许多标签。例如版本号、构建是否针对候选版本等......
我的问题是如何根据标记的管道构建在发布管道中获取这些标签。
[编辑]应用的解决方案
我的实现方式是在命令任务中使用 Bash。唯一的依赖项是一个名为“myvars.pat”的(秘密)变量。这是为此特定情况创建的个人访问令牌。我使用了一个变量组来与不同的发布管道共享令牌。
# 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 …Run Code Online (Sandbox Code Playgroud) azure-devops azure-pipelines azure-pipelines-release-pipeline