Set up runner step fails on Windows self-hosted runner when `ACTIONS_RUNNER_HOOK_JOB_STARTED` set to powershell script
See original GitHub issueDescribe 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
- Current runner version: ‘2.290.0’
- Self-Hosted Windows Server 2019 (https://github.com/actions/virtual-environments/commit/06446ddb68fa8afa21cd8d2676a1757cbf6e9ce3)
What’s not working?
Based on the diag output, we resolve the absolute path of the shell using GetDefaultShellForScript in JobHookProvider
:
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:
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:
- Created a year ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top GitHub Comments
Hi @omsmith,
Thank you for submitting this issue and explaining it so clearly. We will notify you as soon as the fix is ready ☺️
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 🥺 FromTo