Skip to content

Fix Windows container PATH being dropped after a $GITHUB_PATH write#10

Open
bugale wants to merge 1 commit into
sirredbeard:mainfrom
bugale:fix/windows-container-path
Open

Fix Windows container PATH being dropped after a $GITHUB_PATH write#10
bugale wants to merge 1 commit into
sirredbeard:mainfrom
bugale:fix/windows-container-path

Conversation

@bugale

@bugale bugale commented Jun 14, 2026

Copy link
Copy Markdown

Closes #9

Problem

On a Windows container: job, after any step writes $GITHUB_PATH, every later in-container step fails to launch its shell:

hcs::System::CreateProcess: powershell ...: The system cannot find the file specified. (0x2)   # exit 126/127

When a step appends to $GITHUB_PATH, ContainerStepHost.ExecuteAsync re-execs with an explicit override docker exec -e PATH="<prepend>:<ContainerRuntimePath>". ContainerRuntimePath is read once at container start from docker inspect .Config.Env (DockerUtil.ParsePathFromConfigEnv). On Windows that base is empty: typical Windows images (servercore, nanoserver, the dotnet images) don't declare Path in .Config.Env — a Windows container's real PATH only exists at runtime. The override therefore drops System32/PowerShell, and the segments were joined with a POSIX :.

Fix

  • ContainerOperationProvider: when .Config.Env has no PATH on Windows, read the container's real PATH via docker exec <id> cmd /c echo %PATH%.
  • ContainerStepHost.ExecuteAsync: join with Path.PathSeparator instead of :.

Testing

  • dotnet build clean; existing DockerUtilL0, StepHostL0, ContainerOperationProviderL0 tests pass (61).
  • End-to-end against a real Windows container: the exact broken command line (-e PATH="<prepend only>") fails with hcs::CreateProcess 0x2 / exit 127; with the container's live PATH appended and ; separator the shell launches, the prepended dir stays first, and System32 is present (exit 0).

Linux is unaffected: Path.PathSeparator is : there, and the live-PATH read is Windows-only and only triggers when .Config.Env has no PATH.

On Windows, docker inspect .Config.Env rarely contains the container's PATH
(servercore/nanoserver and most images don't declare it), so
ParsePathFromConfigEnv returns empty. The later docker exec -e PATH= override
then replaces the container PATH with only the prepended dirs -- System32 and
PowerShell vanish and the next step's shell can't launch (hcs::CreateProcess
0x2, exit 126/127). PATH segments were also joined with a POSIX ':' separator.

Read the container's real PATH at startup when .Config.Env has none, and join
with Path.PathSeparator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows container: job — container PATH dropped after a step writes $GITHUB_PATH (shell fails to launch, exit 126/127)

1 participant