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

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

问题描述

我已经在我的 TFS/AzureDevops Build 定义中定义了一个变量(假设是 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,你有什么)中,并将其作为构建工件附加.这样你就可以读取发布中的文件并再次设置变量.

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天全站免登陆