如何从TFS/AzureDevOps中获取从构建到发布管道的变量值? [英] How to get the variable value in TFS/AzureDevOps from Build to Release Pipeline?

本文介绍了如何从TFS/AzureDevOps中获取从构建到发布管道的变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的TFS/AzureDevops构建定义中定义了一个变量(假设它为time) 并在我的构建定义中使用PowerShell任务分配值.

I've defined a variable in my TFS/AzureDevops Build definition (say it's time) and assign the value using PowerShell task within my build definition.

就像

类型:内联脚本.

内嵌脚本:

$date=$(Get-Date -Format g);
Write-Host "##vso[task.setvariable variable=time]$date"

您可以参考此类似示例

现在,我想在发布定义管道中获取此值.我将此构建定义配置为持续部署到我的发布定义.

Now I want to get this value in my release definition pipeline. I configured this build definition as continuous deployment to my release definition.

如何使用其他变量在发布定义中获取time的值?这可能吗?

How can I get the value of time in my release definition using some other variable? Is this possible?

推荐答案

这不是将变量从Build传递到Release的正式方法.实现此目的的唯一方法是将值存储在文件(json,xml,yaml等)中,并将其附加为Build Artifact.这样,您可以读取发行版中的文件,然后再次设置变量.

The is no official way to pass variables from Build to Release. The only way to accomplish this is to store the values in a file (json, xml, yaml, what have you) and attach that as a Build Artifact. That way you can read the file in the release and set the variable again.

马丁·欣希尔伍德(Martin Hinshelwood)似乎已经对这个问题感到沮丧,并且已将该功能转变为扩展功能适用于Azure DevOps管道.

Martin Hinshelwood seems to have gotten frustrated enough by this problem and turned that functionality into an extension for Azure DevOps Pipelines.

包含的任务

  • 变量保存任务-在构建期间,您可以将变量保存到与其他构建资产一起存储的json文件中
  • 变量加载任务-在发布期间,您可以加载保存的变量并获得对它们的访问权限.

Tasks included

  • Variable Save Task - During your build you can save the variables to a json file stored with your other build assets
  • Variable Load Task - During your Release you can load the saved variables and gain access to them.

这篇关于如何从TFS/AzureDevOps中获取从构建到发布管道的变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆