本文介绍了TFS Build vNext:如何从 Powershell 写入自定义构建变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要设置自定义构建变量的 Powershell 脚本,以便它可以在以后的任务中使用.我已经成功添加了一个变量,并验证它可以从 Powershell 访问和设置,但是,无论出于何种原因,在稍后的构建步骤中引用该变量时,更改不会持续.

I have a Powershell script that needs to set a custom build variable, such that it can be used in a later task. I have successfully added a variable, and verified it can be accessed and set from Powershell, but, for whatever reason, the change does not persist when referencing the variable in a later build step.

Write-Host $env:VERSIONNUMBER #prints the variable value set in TFS Build
$env:VERSIONNUMBER = 'This doesn't stick'
Write-Host $env:VERSIONNUMBER #prints 'This doesn't stick', but not available after this task

推荐答案

在您的 PowerShell 脚本中尝试以下操作

Try the following in your PowerShell script

Write-Host "##vso[task.setvariable variable=myvariable]newValue"

这在 Release Management vNext 中对我有用,但我认为它也适用于构建系统.

this worked for me in Release Management vNext, but I would assume it also works in the build system as well.

这篇关于TFS Build vNext:如何从 Powershell 写入自定义构建变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:08