在 Azure Pipeline 构建中刷新环境变量

Refresh environment variables in Azure Pipeline build

如何为间接更改这些变量的同一构建中的后续步骤刷新环境变量?

重现所述行为的测试 YAML 文件部分。

jobs:
- job: welldone
  pool: 
    name: noodle
  steps:
  - script: |
      echo select TestStand 2016
      start /wait "" "C:\Program Files (x86)\National Instruments\Shared\TestStand Version Selector\TSVerSelect.exe" /version 16.0 /installing /noprompt
    displayName: 'select TestStand version 16'

  - script: |
      echo Check TestStand version
      echo %TestStand%
      call RefreshEnv.cmd
      echo %TestStand%
    displayName: 'print TestStand version'

  - script: |
      call checkTSversion.bat
      call RefreshEnv.cmd
      call checkTSversion.bat
    displayName: 'call bat file to print TestStand version'

第一个脚本调用 TestStand Version Selector 更改环境变量等。

第二个脚本打印以 "teststand" 开头的环境变量,然后调用 refreshenv.cmd 并再次打印变量。首先打印旧变量,其次 - 更新。我想这与 cmd 的预期行为一致。

3rd 脚本执行相同的操作,但现在 echo %TestStand% 位于单独的批处理文件中。它的行为与第二个脚本完全一样。

我可以在第一个脚本中做什么以确保连续的脚本将读取更新的环境变量?

我不完全确定我理解你的示例管道,但在我看来你想要设置变量 and/or 在作业步骤中更改变量值,然后在稍后使用新值工作步骤。正确的?如果是这样,您正在寻找这样的东西:

steps:
# Create a variable
# Note that this does _not_ update the environment of the current script.
- bash: |
    echo "##vso[task.setvariable variable=sauce]crushed tomatoes"

# An environment variable called `SAUCE` has been added to all downstream steps
- bash: |
    echo "my environment variable is $SAUCE"
- pwsh: |
    Write-Host "my environment variable is $env:SAUCE"

来源:https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#set-variables-in-scripts