exec: "pwsh": executable file not found in %PATH%
Asked Answered
B

4

41

I've been trying to initiate my pipeline on gitlab CI/CD for a demo project. I've installed gitlab-runner in my windows local machine and gave the executor type as "Shell". And I've successfully integrated the gitlab-runner with my gitlab project. But whenever I pushed any changes to repo, the pipeline started and end up in "pshw" not found in %PATH error. This is error which I'm getting every time

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

Can anyone help me to resolve this issue and explain what and why I'm getting this error.

Thanks in advance

Beverly answered 24/6, 2021 at 3:28 Comment(0)
T
70

When choosing the shell option, the gitlab runner installer uses pwsh as the executor. It generates a config.toml that looks like

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

The problem is that pwsh isn't a valid windows command (on my installs). Changing pwsh to powershell and restarting gitlab-runner service fixed the problem for me.

Tyrontyrone answered 25/6, 2021 at 10:21 Comment(4)
How do you change the default shell to powershell in the install itself, while doing another install I'm still getting the default shell as pwsh instead of powershellTilghman
@Clueless, Apparently, one cannot specify this during installation/registration rather changing the config.toml fileEncephalo
This is not a solution in case you need features from Powershell Core (pwsh)Megillah
The answer isn't much use if you need to use PowerShell CoreCeric
S
25

Go to the installation directory of GitLab Runner e.g. C:\Automation\GitLab-Runner. Here you will see config.toml file, open with notepad and replace "pwsh" with "powershell" as below:

From:

[[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"       # <----- 
Sunward answered 23/7, 2021 at 1:34 Comment(0)
M
6

The current answers from "Raghwendra Sonu" and "Not a code monkey" work if you do not need features from Powershell Core (v7) and you are fine with using Windows Powershell (v5). If you do need features from Powershell Core then editing your config.toml is not a solution.

I had the same problem — I installed Powershell Core from the Microsoft Store and added it to the PATH Environment variable (happened automatically), but I still got the mentioned error within gitlab.

The solution is to not use the Powershell Core from the Microsoft Store, but instead install it like this (at least that worked for me):

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

And then add it to the PATH via adding C:\Program Files\PowerShell\7 to the PATH.

I hope that helps.

Megillah answered 28/4, 2023 at 2:1 Comment(2)
This is it! Thank you so much, exactly what I was looking for. I just could not for the life of me find the path to PowerShell...Sped
It also took me a while to find that out :)Megillah
R
0

You can specify shell during registration with --shell parameter, e.g. bash, sh, cmd, pwsh or powershell.

PS> .\gitlab-runner.exe register `
  --non-interactive `
  --url "https://gitlab.com/" `
  --token "TOKEN" `
  --executor "shell" `
  --shell "powershell" `
  ...
Rue answered 2/1 at 16:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.