VSTS:无法更改版本中用户定义变量的值

VSTS: Cannot change value of a user defined variable in release

因此,我创建了初始值为 -1 的变量 counter

然后在 Release 中,我尝试使用 Powershell 脚本将其值更改为 1:

但值没有改变:

但是,我在 Build 中对此进行了测试,它按预期工作。我错过了什么吗?

此命令的目的是设置一个跨任务持续存在的变量。因此,它只能保证在您 运行 的下一个 PowerShell 任务中可用,因为它可能需要一点时间才能生效(您的构建可能很幸运,但实际上这是一个竞争条件)。 文档 here 支持这样一个事实,即在以后使用变量之前,您应该在其自己的任务中定义变量:

Sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable. When issecret is set to true, the value of the variable will be saved as secret and masked out from log. Secret variables are not passed into tasks as environment variables and must be passed as inputs.

Write-Host "##vso[task.setvariable variable="counter"] 1"替换为Write-Host "##vso[task.setvariable variable=counter] 1"(来自"counter"的远程双引号)