You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab CI Runner报错:FATAL: Command sh not found 求助

Hey there, let's figure out why you're hitting that "FATAL: Command sh not found" error with your Docker-installed GitLab Runner. Given your setup (GitLab 10.4.3, Runner 10.7.2), here are the most common fixes to check step by step:

1. Confirm your job's Docker image includes a shell

First up: if your .gitlab-ci.yml specifies a custom Docker image for jobs, that image might not have /bin/sh or /bin/bash installed. For example:

  • Super minimal images like scratch don't include any shell utilities at all. Swap to a base image like alpine:latest, debian:slim, or ubuntu:latest—these all come with a shell by default.
  • To test locally, run docker run --rm <your-job-image> sh -c "echo test"—if this fails, the image is missing sh, and that's the root cause.

2. Double-check your Runner's config.toml settings

Since you're using the Docker executor (the standard setup for Docker-installed Runners), make sure your config isn't pointing to a non-existent shell path. Open your config.toml and look for the runner section:

[[runners]]
  executor = "docker"
  [runners.docker]
    image = "alpine:latest"  # This should be an image with sh
    shell = "sh"  # Don't set this to a path that doesn't exist in the image
  • If you've set shell to something like /bin/zsh but the image doesn't have it, or made a typo (like shh), that'll trigger the error. Stick to sh or bash depending on what your base image provides.
  • Also, make sure you didn't accidentally set the executor to shell instead of docker—the Runner container itself might not have the right shell setup for the shell executor.

3. Audit your .gitlab-ci.yml job scripts

Look for any job configurations that might be bypassing or misusing the shell:

  • If you're using array syntax for script (like script: ["my-command"]) and the command relies on shell features (pipes, environment variables, wildcards), you'll need to wrap it in a shell explicitly:
    build-job:
      script:
        - sh -c "echo $CI_JOB_ID | grep -E '[0-9]+'"
    
  • Avoid setting a shell: key in your job unless you're 100% sure that shell exists in the job's image.

4. Verify the GitLab Runner container has sh (if using shell executor)

If you're actually using the shell executor with your Dockerized Runner, the Runner's own container needs to have sh available. Check by running:

docker exec -it <your-runner-container-name> sh

If this fails, you might need to use the official GitLab Runner image (which should include sh by default) or install shell utilities inside the container (though modifying the Runner container isn't ideal—better to stick to the official image).

After making any changes, restart your Runner container to apply updates:

docker restart gitlab-runner

内容的提问来源于stack exchange,提问作者Splitframe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:47:21