actions / actions/runner

PWSH 7.1.3 fails with exit code 1 when stderr is redirected to stdout

Open
#1,076 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
6.3k
Forks
1.4k
Avg merge
1d 16h
Merged PRs (30d)
24

Description

Describe the bug
When pwsh (latest: v7.1.3) action on Windows contains stderr -> stdout redirection (e.g.: a simple 2>&1) the action fails with ExitCode 1

To Reproduce
Simply add the following line to windows-2019 action:

- name: STDERR redirection test
  run: $E = $(Write-Error "oops" 2>&1)

Expected behavior

$E = $(Write-Error "oops" 2>&1)

should not cause the build to fail and $E variable should be assigned the value Write-Error: oops

Runner Version and Platform

Current runner version: '2.278.0'
Operating System
  Microsoft Windows Server 2019
  10.0.17763
  Datacenter
Virtual Environment
  Environment: windows-2019
  Version: 20210425.1
  Included Software: https://github.com/actions/virtual-environments/blob/win19/20210425.1/images/win/Windows2019-Readme.md
  Image Release: https://github.com/actions/virtual-environments/releases/tag/win19%2F20210425.1

What's not working?

Run $E = $(Write-Error "oops" 2>&1)
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
Write-Error: oops
Error: Process completed with exit code 1.

Job Log Output

Run $E = $(Write-Error "oops" 2>&1)
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
Write-Error: oops
Error: Process completed with exit code 1.

NB: This is different from #169
The code example from #169 :

run: |
  npm ping
  npm ping
  npm ping

does work with the latest version of the runner but 2>&1 does not.

When $E = $(Write-Error "oops" 2>&1) is executed in my local pwsh it works as expected:

PS \> $E = $(Write-Error "oops" 2>&1)
PS \> $lastExitCode
0
PS \> $E
Write-Error: oops

but fails with ExitCode 1 when executed as a part of github action. Both, my pwsh and github action pwsh seem to be of the same version: 7.1.3.
Combined test with version included:

- name: STDERR redirection test
  run: |
    $host.Version
    npm ping
    npm ping
    npm ping
    $E = $(Write-Error "oops" 2>&1)

outputs:

Run $host.Version
  $host.Version
  npm ping
  npm ping
  npm ping
  $E = $(Write-Error "oops" 2>&1)
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

Major  Minor  Build  Revision
-----  -----  -----  --------
7      1      3      -1
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.527ms
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.277ms
npm notice PING https://registry.npmjs.org/
npm notice PONG 0.269ms
Write-Error: oops
Error: Process completed with exit code 1.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the pwsh command in a Windows 2019 GitHub Actions job using runner version 2.278.0 and PowerShell 7.1.3. Compare the redirected Write-Error behavior with local PowerShell; done means the command assigns $E without causing the action to exit with code 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, powershell
Domain
ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.