exec: "pwsh": 可执行文件在 %PATH% 中未找到

39

我一直在尝试在GitLab CI/CD上启动我的演示项目的流水线。我在Windows本地机器上安装了gitlab-runner并将执行程序类型设置为“Shell”。我已经成功地将gitlab-runner集成到我的gitlab项目中。但是每当我推送更改到存储库时,流水线就会开始并以“%PATH未找到pshw”错误结束。 这是我每次遇到的错误

ERROR: Job failed (system failure): prepare environment: failed to start process: exec: "pwsh": executable file not found in %PATH%. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

有谁能帮我解决这个问题并解释一下我为什么会遇到这个错误。

提前感谢。

3个回答

65

选择 shell 选项时,gitlab runner 安装程序使用 pwsh 作为执行器。它生成一个类似于config.toml的文件。

[[runners]]
  name = "some name"
  url = "http://someurl.com/"
  token = "some-token"
  executor = "shell"
  shell = "pwsh"

问题在于 pwsh 不是一个有效的 Windows 命令(在我的安装中)。将 pwsh 更改为 powershell 并重新启动 gitlab-runner 服务,解决了我的问题。


在安装过程中如何将默认 shell 更改为 PowerShell?即使进行另一个安装,我仍然会得到 pwsh 作为默认 shell 而不是 PowerShell。 - Clueless
1
@Clueless,显然,在安装/注册过程中无法指定此项,而应更改 config.toml 文件。 - ddsultan
如果您需要 Powershell Core(pwsh)的功能,则这不是一种解决方案。 - Ini
如果你需要使用PowerShell Core,那么这个答案就没有太多用处了。 - undefined

21

前往GitLab Runner的安装目录,例如C:\Automation\GitLab-Runner。在这里你会看到config.toml文件,用记事本打开并按照以下方式将"pwsh"替换为"powershell"

原文:

[[runners]]
  name = "PT-Runner"
  url = "https://gitlab.com"
  executor = "shell"
  shell = "pwsh"             # <----- change to powershell

To:

[[runners]]
  name = "PT-Runner"
  url = "https://gitlab.com"
  executor = "shell"
  shell = "powershell"       # <----- 

4

"Raghwendra Sonu"和"Not a code monkey"目前提供的答案适用于不需要Powershell Core(v7)功能且可以使用Windows Powershell(v5)的情况。如果您确实需要Powershell Core的功能,则编辑config.toml并不是解决方案。

我也遇到了同样的问题-我从Microsoft Store安装了Powershell Core并将其添加到PATH环境变量中(自动发生),但我仍然在gitlab中遇到了上述错误。

解决方案是不要使用来自Microsoft Store的Powershell Core,而是像这样安装它(至少对我有效):

winget install --id Microsoft.Powershell --source winget

然后通过将C:\Program Files\PowerShell\7添加到PATH中来将其添加到PATH中。

希望这有所帮助。


1
就是这样!非常感谢,正是我一直在寻找的。但我就是找不到PowerShell的路径... - MinestoPix
我也花了一些时间才弄清楚这个 :) - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接