question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set up runner step fails on Windows self-hosted runner when `ACTIONS_RUNNER_HOOK_JOB_STARTED` set to powershell script

See original GitHub issue

Describe the bug Set up runner step fails on Windows self-hosted runner when ACTIONS_RUNNER_HOOK_JOB_STARTED set to powershell script.

Runner Version and Platform

What’s not working?

Based on the diag output, we resolve the absolute path of the shell using GetDefaultShellForScript in JobHookProvider:

https://github.com/actions/runner/blob/eb9a604b63d9d656beee60c84e03d3cd87485496/src/Runner.Worker/JobHookProvider.cs#L63

This absolute path is C:\Program Files\PowerShell\7\pwsh.EXE, and the full shell string being C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

In ScriptHandler we parse that string using ParseShellOptionString:

https://github.com/actions/runner/blob/44d4d076fec3fddaf68c876cbea2217110d48892/src/Runner.Worker/Handlers/ScriptHandler.cs#L103

Which splits on a space: https://github.com/actions/runner/blob/d081289ed53841c9d78c3e796c429965c4fe5d58/src/Runner.Worker/Handlers/ScriptHandlerHelpers.cs#L70

Leading to a result of (shellCommand: "C:\Program", shellArgs: "Files\PowerShell\7\pwsh.EXE");

Easiest fix I’m seeing would be do not provide the absolute path in GetDefaultShellForScript and just provide the program name (pwsh) after selecting it.

Job Log Output

##[debug]Evaluating condition for step: 'Set up runner'
##[debug]Evaluating: always()
##[debug]Evaluating always:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Set up runner
A job started hook has been configured by the self-hosted runner administrator
Run 'C:\runner\detach-on-receiving-job.ps1'
  Error: Second path fragment must not be a drive or UNC name. (Parameter 'expression')
  ##[debug]System.ArgumentException: Second path fragment must not be a drive or UNC name. (Parameter 'expression')
  ##[debug]   at System.IO.Enumeration.FileSystemEnumerableFactory.NormalizeInputs(String& directory, String& expression, MatchType matchType)
  ##[debug]   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
  ##[debug]   at GitHub.Runner.Sdk.WhichUtil.Which(String command, Boolean require, ITraceWriter trace, String prependPath)
  ##[debug]   at GitHub.Runner.Worker.Handlers.ScriptHandler.PrintActionDetails(ActionRunStage stage)
  ##[debug]   at GitHub.Runner.Worker.Handlers.Handler.PrepareExecution(ActionRunStage stage)
  ##[debug]   at GitHub.Runner.Worker.JobHookProvider.RunHook(IExecutionContext executionContext, Object data)
  ##[debug]   at GitHub.Runner.Worker.JobExtensionRunner.RunAsync()
  ##[debug]   at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
  ##[debug]Finishing: Set up runner

Runner and Worker’s Diagnostic Logs

[2022-04-14 02:19:14Z INFO ExecutionContext] Publish step telemetry for current step {
  "action": "setup_job",
  "type": "runner",
  "stage": "Pre",
  "stepId": "a37e80ad-ef0c-4281-9200-b0670b19898f",
  "result": "succeeded",
  "errorMessages": [],
  "executionTimeInSeconds": 1
}.
[2022-04-14 02:19:14Z INFO JobRunner] Total job steps: 2.
[2022-04-14 02:19:14Z INFO JobRunner] Run all job steps.
[2022-04-14 02:19:14Z INFO StepsRunner] Processing step: DisplayName='Set up runner'
[2022-04-14 02:19:14Z INFO StepsRunner] Evaluating: always()
[2022-04-14 02:19:14Z INFO StepsRunner] Result: true
[2022-04-14 02:19:14Z INFO StepsRunner] Starting the step.
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Bin': 'C:\runner\dist\bin'
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Root': 'C:\runner\dist'
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Work': 'C:\runner\work'
[2022-04-14 02:19:14Z INFO StepsRunner] Which: 'chcp'
[2022-04-14 02:19:14Z INFO JobServerQueue] Try to append 1 batches web console lines for record 'a37e80ad-ef0c-4281-9200-b0670b19898f', success rate: 1/1.
[2022-04-14 02:19:14Z INFO JobServerQueue] Try to append 1 batches web console lines for record 'f36c4491-b5ff-4e70-ad36-461bcc8553b5', success rate: 1/1.
[2022-04-14 02:19:14Z INFO JobServerQueue] Job timeline record has been updated for the first time.
[2022-04-14 02:19:14Z INFO StepsRunner] Location: 'C:\Windows\system32\chcp.COM'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper] Starting process:
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   File name: 'C:\Windows\system32\chcp.COM'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Arguments: '65001'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Working directory: 'C:\runner\work'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Require exit code zero: 'False'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Encoding web name:  ; code page: ''
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Force kill process on cancellation: 'False'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Redirected STDIN: 'False'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Persist current code page: 'True'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   Keep redirected STDIN open: 'False'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper]   High priority process: 'False'
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper] Process started with process id 5044, waiting for process exit.
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper] STDOUT/STDERR stream read finished.
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper] STDOUT/STDERR stream read finished.
[2022-04-14 02:19:14Z INFO ProcessInvokerWrapper] Finished process 5044 with exit code 0, and elapsed time 00:00:00.0830130.
[2022-04-14 02:19:14Z INFO StepsRunner] Successfully returned to code page 65001 (UTF8)
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Bin': 'C:\runner\dist\bin'
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Root': 'C:\runner\dist'
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Work': 'C:\runner\work'
[2022-04-14 02:19:14Z INFO HostContext] Well known directory 'Temp': 'C:\runner\work\_temp'
[2022-04-14 02:19:14Z INFO ExecutionContext] Write event payload to C:\runner\work\_temp\_github_workflow\event.json
[2022-04-14 02:19:14Z INFO JobHookProvider] Which: 'pwsh'
[2022-04-14 02:19:15Z INFO JobHookProvider] Location: 'C:\Program Files\PowerShell\7\pwsh.EXE'
[2022-04-14 02:19:15Z INFO ExtensionManager] Getting extensions for interface: 'GitHub.Runner.Worker.IActionCommandExtension'
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.InternalPluginSetRepoPathCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.SetEnvCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.SetOutputCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.SaveStateCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.AddPathCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.AddMaskCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.AddMatcherCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.RemoveMatcherCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.WarningCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.ErrorCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.NoticeCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.DebugCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.GroupCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.EndGroupCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ExtensionManager] Creating instance: GitHub.Runner.Worker.EchoCommandExtension, Runner.Worker
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command internal-set-repo-path
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command set-env
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command set-output
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command save-state
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command add-path
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command add-mask
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command add-matcher
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command remove-matcher
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command warning
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command error
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command notice
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command debug
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command group
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command endgroup
[2022-04-14 02:19:15Z INFO ActionCommandManager] Register action command extension for command echo
[2022-04-14 02:19:15Z INFO ScriptHandler] Which: 'C:\Program'
[2022-04-14 02:19:15Z INFO JobServerQueue] Try to append 1 batches web console lines for record 'f36c4491-b5ff-4e70-ad36-461bcc8553b5', success rate: 1/1.
[2022-04-14 02:19:15Z INFO JobServerQueue] Try to upload 1 log files or attachments, success rate: 1/1.
[2022-04-14 02:19:16Z ERR  StepsRunner] Caught exception from step: System.ArgumentException: Second path fragment must not be a drive or UNC name. (Parameter 'expression')
   at System.IO.Enumeration.FileSystemEnumerableFactory.NormalizeInputs(String& directory, String& expression, MatchType matchType)
   at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at GitHub.Runner.Sdk.WhichUtil.Which(String command, Boolean require, ITraceWriter trace, String prependPath)
   at GitHub.Runner.Worker.Handlers.ScriptHandler.PrintActionDetails(ActionRunStage stage)
   at GitHub.Runner.Worker.Handlers.Handler.PrepareExecution(ActionRunStage stage)
   at GitHub.Runner.Worker.JobHookProvider.RunHook(IExecutionContext executionContext, Object data)
   at GitHub.Runner.Worker.JobExtensionRunner.RunAsync()
   at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
[2022-04-14 02:19:16Z INFO StepsRunner] Step result: Failed
[2022-04-14 02:19:16Z INFO ExecutionContext] Publish step telemetry for current step {
  "action": "set_up_runner",
  "type": "runner",
  "stage": "Pre",
  "stepId": "f36c4491-b5ff-4e70-ad36-461bcc8553b5",
  "result": "failed",
  "errorMessages": [
    "Second path fragment must not be a drive or UNC name. (Parameter 'expression')"
  ],
  "executionTimeInSeconds": 2
}.
[2022-04-14 02:19:16Z INFO StepsRunner] Update job result with current step result 'Failed'.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nikola-jokiccommented, Apr 14, 2022

Hi @omsmith,

Thank you for submitting this issue and explaining it so clearly. We will notify you as soon as the fix is ready ☺️

0reactions
wozzocommented, Jan 20, 2023

In case anyone else comes here with this issue, in my case I’d used " in the .env file do point to the file path. This was a mistake 🥺 From

ACTIONS_RUNNER_HOOK_JOB_STARTED="C:/a-path/job-to-run.ps1"

To

ACTIONS_RUNNER_HOOK_JOB_STARTED=C:/a-path/job-to-run.ps1
Read more comments on GitHub >

github_iconTop Results From Across the Web

github runner on Windows not finding executables ...
I am trying to use a self-hosted Windows-VM to run west for repo management, python to run some scripts, and git to push...
Read more >
Using PowerShell script Setup Self-hosted Windows GitHub ...
Using PowerShell script Setup Self-hosted Windows GitHub Actions Runner on AWS EC2 in Private Subnet. 1 view · 6 minutes ago ...more ...
Read more >
Set up runners for Windows | Bitbucket Cloud
Open PowerShell as an administrator, go to the bin directory under your Runner folder, run the command provided in Run step on the...
Read more >
Fix for PowerShell Script cannot be loaded because ...
Root Cause: This is due to the Windows PowerShell execution policy being set to prevent untrusted scripts which can affect your Windows client...
Read more >
Windows PowerShell failed still marks job successful (#3194)
Summary A Powershell command failed, job stopped (while there are some other script lines) but it succeeded. It mustn't.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found