38

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

Aravind S
  • 381
  • 1
  • 3
  • 5

3 Answers3

62

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.

phoenix
  • 7,988
  • 6
  • 39
  • 45
  • 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 powershell – Clueless Jan 18 '22 at 07:55
  • 1
    @Clueless, Apparently, one cannot specify this during installation/registration rather changing the `config.toml` file – ddsultan Feb 22 '22 at 13:29
  • This is not a solution in case you need features from Powershell Core (`pwsh`) – Ini Apr 28 '23 at 02:02
21

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"       # <----- 
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Raghwendra Sonu
  • 471
  • 3
  • 7
3

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.

Ini
  • 548
  • 7
  • 19
  • 1
    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... – MinestoPix Jun 04 '23 at 12:40