gitlab-runner: prepare environment failed to start process pwsh in windows
Asked Answered
F

3

29

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
Franconian answered 19/6, 2021 at 19:33 Comment(0)
F
65

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
Franconian answered 19/6, 2021 at 19:33 Comment(3)
This fixed the issue in Windows Server 2019 as well.Sasha
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.Duran
just a little note for windows server. winget is not supported, so to install the new powershell, you need to download the .msi package : learn.microsoft.com/en-us/powershell/scripting/install/…Thissa
D
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

Disclose answered 17/3, 2022 at 8:31 Comment(0)
I
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
Idolater answered 14/1, 2022 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.