在 GitHub 个操作中获得 "StandardOutputEncoding is only supported when standard output is redirected"

Getting "StandardOutputEncoding is only supported when standard output is redirected" in GitHub Actions

我 运行 gitversion.exe 作为 GitHub 操作工作流程的一部分 Windows 使用 pwsh:

$versionInfo = (& .\gitversion.exe) | ConvertFrom-Json

虽然在我的本地机器上工作得很好,但它在动作运行器上失败了:

ResourceUnavailable: D:\a\azure-pipelines-pre-and-post-tasks\azure-pipelines-pre-and-post-tasks\build.ps1:178
Line |
 178 |  $versionInfo = (& .\gitversion.exe) | ConvertFrom-Json
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Program 'gitversion.exe' failed to run: StandardOutputEncoding is only supported when standard output
     | is redirected.At
     | D:\a\azure-pipelines-pre-and-post-tasks\azure-pipelines-pre-and-post-tasks\build.ps1:178 char:17 +
     | $versionInfo = (& .\gitversion.exe) | ConvertFrom-Json +                 ~~~~~~~~~~~~~~~~~~.

我是 运行 其他可执行文件并在同一个脚本中毫无问题地捕获它们的输出,所以 gitversion 肯定有一些我不完全理解的特别之处。

具有当前可重现行为的回购协议在此处:

好吧,这是出乎意料的。首先,我偶然发现了更改 PowerShell 控制台输入和输出编码的提示:

[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

这揭示了一个新问题,即 gitversion.exe 不是有效的 windows 可执行文件。原来是LFS指针文件

ResourceUnavailable: D:\a\azure-pipelines-pre-and-post-tasks\azure-pipelines-pre-and-post-tasks\build.ps1:179
Line |
 179 |  $versionInfo = & .\gitversion.exe | ConvertFrom-Json
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Program 'gitversion.exe' failed to run: An error occurred trying to start process
     | 'D:\a\azure-pipelines-pre-and-post-tasks\azure-pipelines-pre-and-post-tasks\gitversion.exe' with
     | working directory 'D:\a\azure-pipelines-pre-and-post-tasks\azure-pipelines-pre-and-post-tasks'. The
     | specified executable is not a valid application for this OS platform.

我忘记补充了:

with:
  lfs: true

我的结帐任务:

steps:
- uses: actions/checkout@v2
  with:
    lfs: true

无论操作系统抛出什么错误,都会导致此 post 标题中的错误。但真正的问题是缺少实际的可执行文件。