28

On a new WIN10 machine after installing gitlab-runner with shell executor(i.e powershell) and starting a CI build throws following error:

Preparing environment
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
harish
  • 1,836
  • 3
  • 21
  • 26

3 Answers3

62

pwsh entry for the shell attribute in gitlab-runner config.toml refers to the newer powershell(pwsh.exe) and does not come pre-installed in some WIN10 machines which contain only older powershell.exe. You can do one of following solutions:

Solution 1: Open a CMD or powershell window and install the newer pwsh.exe:

winget install Microsoft.PowerShell

Solution 2: Edit your config.toml to use the older powershell.exe:

From

[[runners]]
  name = "ci-runner"
  url = "http://xxx.yyy.xx/"
  token = "XXXXX"
  executor = "shell"
  shell = "pwsh"

To

[[runners]]
  name = "ci-runner"
  url = "http://xxx.yyy.xx/"
  token = "XXXXX"
  executor = "shell"
  shell = "powershell"

And then restarting gitlab-runner fixed the issue.

gitlab-runner.exe restart
harish
  • 1,836
  • 3
  • 21
  • 26
  • 2
    This fixed the issue in Windows Server 2019 as well. – hooinator Sep 07 '21 at 13:52
  • 1
    There should be more context here: `pwsh` will run *Powershell Core* (v.5.1+), while `powershell` runs *Powershell Desktop* (prior versions). Therefore those two are not the same. You can fix your original issue by installing newest version of PowerShell (for me v7.x) and make sure that your PATH env variable points to the installation dir where `pwsh.exe` lies. – ŁukaszBachman Feb 01 '22 at 09:31
  • 1
    just a little note for windows server. winget is not supported, so to install the new powershell, you need to download the .msi package : https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2#installing-the-msi-package – ihebiheb Aug 15 '22 at 02:59
1

After running gitlab cicd runner you will get a file named config.tomal change :

shell = "pwsh" to shell = "powershell" after getting solution getting error

0

If you are on Windows, You can use docker instead shell when the value of executor is asking to you, with gitlab/gitlab-runner as default image. It works for me.

More infos here:

  1. GitLab Runner
  2. Registering runners # Windows | GitLab

My config.toml file looks like (dev env):

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Your name here"
  url = "https://gitlab.com/"
  token = "Your token"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "gitlab/gitlab-runner"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0