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

Viewed 10936

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
3 Answers

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

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

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

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

Related