gitlab-runner:准备环境无法在 windows 中启动进程 pwsh

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

在使用 shell 执行器(即 powershell)安装 gitlab-runner 并启动 CI 构建后,在新的 WIN10 机器上抛出以下错误:

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

pwsh gitlab-runner 中 shell 属性的条目 config.toml 指的是较新的 powershell(pwsh.exe) 并且在某些 WIN10 中没有预装仅包含旧 powershell.exe 的机器。您可以执行以下解决方案之一:

解决方案 1:打开 CMD 或 powershell window 并安装更新的 pwsh.exe:

winget install Microsoft.PowerShell

解决方案 2:编辑您的 config.toml 以使用旧的 powershell.exe:

来自

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

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

然后重启 gitlab-runner 解决了这个问题。

gitlab-runner.exe restart

如果您使用 Windows,您可以使用 docker 而不是 shell executor 的值向您询问,默认图像为 gitlab/gitlab-runner。它对我有用。

更多信息在这里:

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

我的 config.toml 文件看起来像 (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

在 运行 gitlab cicd runner 之后你会得到一个名为 config.tomal 的文件 变化:

shell = "pwsh" 到 shell = "电源shell"