在我的构建管道中,我有一个 powershell 任务,它执行脚本以从构建中收集信息。
它需要从环境变量中获取的代理和构建变量。
问题是:没有填充环境变量。
当我运行这个脚本时,我得到一个空的结果:
Write-Host "Before"
Get-ChildItem env: | ft Name, Value -AutoSize | Out-String | Write-Host
Write-Host "After"
当我使用我的私有构建代理(在 Windows 上)执行此操作时,它运行良好。
构建服务器上的输出:
==============================================================================
Task : PowerShell
Description : Run a PowerShell script on Windows, macOS, or Linux.
Version : 2.136.0
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
Formatted command: . '/home/vsts/work/1/s/build/scripts/GatherDeploymentInfo.ps1'
[command]/usr/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/home/vsts/work/_temp/1125300b-d6df-46f0-a852-041c22d2964f.ps1'
Before
After
解决了:
修复最终是将 buildagent 从“Hosted Linux Preview 2”更改为“Hosted Ubuntu 1604”。这导致所有环境在 powershell 核心中再次可见。