actions / actions/runner

[windows self-hosted] Running as a service doesn't include user PATH env var

Open
#2,540 9 comments 5 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
I've been trying to setup my own windows self-hosted runners for a while now, but every attempt always ran into the same issue: rustup could not be found. For context, Rust installs all of it's tools to ~/.cargo/bin and ~/.rustup. Both of these paths are in the user's PATH environment variable:

echo $env:PATH
C:\Program Files\PowerShell\7;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\PowerShell\7\;C:\Python311\Scripts\;C:\Python311\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\Administrator\.cargo\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\AppData\Roaming\npm

But when steps are ran from the context of a runner, all the PATHs in the user directory are missing. It only includes the system PATH environment variable.

echo $env:PATH
C:\Program Files\PowerShell\7;C:\Program Files\Git\cmd;C:\Program Files\Git\bin;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Amazon\cfn-bootstrap\;C:\Program Files\PowerShell\7\;C:\Python311\Scripts\;C:\Python311\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Microsoft\WindowsApps

I've gone crazy over trying to figure this out. Is it windows security settings? Permission issues? The runner using a different user? The runner misconfigured (everything passed)? Restarting the service. Rebooting the windows OS. So on and so forth.

But I finally figure out the problem. Running the runner as a service does not include the user PATH env var, only system PATH. However, if I stop the service and run ./run.cmd manually from powershell, everything works accordingly!

To Reproduce
Steps to reproduce the behavior:

  1. Setup the runner
  2. Run ./configure.cmd and when it prompts to start as a service -> Yes
  3. Run a job that requires bins found on user's PATH

Expected behavior
Running the runner as a service includes user PATH env var.

Runner Version and Platform

Version of your runner? 2.303.0

OS of the machine running the runner? Windows server 2022 64-bit

What's not working?

Please include error messages and screenshots.

Job Log Output

N/A

Runner and Worker's Diagnostic Logs

N/A

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 with the reported setup flow using configure.cmd, the service option, and run.cmd on Windows Server 2022, comparing the PATH visible to jobs in each mode. Trace how the runner service receives its environment and verify that a service-run job includes the user's PATH entries, including the Rust tool paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
ci-cd, devops, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.