Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure devops 如何从Azure发布管道获取构建管道标记?_Azure Devops_Azure Pipelines_Azure Pipelines Release Pipeline - Fatal编程技术网

Azure devops 如何从Azure发布管道获取构建管道标记?

Azure devops 如何从Azure发布管道获取构建管道标记?,azure-devops,azure-pipelines,azure-pipelines-release-pipeline,Azure Devops,Azure Pipelines,Azure Pipelines Release Pipeline,明确地说:这与Git标记无关。我说的是可以添加到单个管道构建中的标记。例如,当使用日志命令##vso[build.addbuildtag]时 构建管道向其构建添加了许多标记。例如,版本号、构建是否针对候选版本等 我的问题是如何在基于标记管道构建的发布管道中获得这些标记 [编辑]应用的解决方案 我实现的方式是在命令任务中,使用Bash。唯一的依赖项是一个名为“myvars.pat”的(秘密)变量。这是为此特定案例创建的个人访问令牌。我使用了一个变量组与不同的发布管道共享令牌 # Construct

明确地说:这与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 ./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    
如何根据标记的内容在发布管道中获取这些标记 管道建设

对于这个问题,您可以使用RESTAPI来实现它。您可以将powershell任务添加到发布管道,然后通过脚本调用此rest api以在发布中输出构建标记

 GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/tags?api-version=5.1
示例脚本:

$personalAccessToken="{yourPAT}"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($personalAccessToken)"))
$header = @{Authorization=("Basic {0}" -f $token)}
$Url = "https://dev.azure.com/{org}/{pro}/_apis/build/builds/{buildId}/tags?api-version=5.1"
$tags = Invoke-RestMethod -Uri $Url -Method Get  -Headers $header
Write-Host  "Tags = $($tags.value| ConvertTo-Json -Depth 1)"
发布:


您检查过自动变量吗?如果您是指内置变量,那么是的。@JG801好几天没有收到您的回复,请您分享关于这个问题的最新信息。如果您有任何问题,请在这里分享。@HughLin MSFT我目前正在工作中被转移。所以,并不是我不想找到答案。:-)我认为这是最后一项措施。没有其他方法了?目前,我能想到的唯一方法是通过RESTAPI。