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

GitLab CI作业使用哪种Shell?能否自定义指定Shell?

GitLab CI 脚本的Shell类型与自定义指定

1. 脚本默认使用的Shell

GitLab CI在执行script阶段时,会自动覆盖镜像的默认入口点,改用系统默认的Shell来运行命令。对于python:3.10官方镜像(基于Debian/Ubuntu),默认使用的是sh(实际指向dash)。这也是为什么你在CI里能执行cd这类Shell命令,而本地直接运行镜像会进入Python REPL——本地运行时用的是镜像默认的python入口点,CI则替换成了Shell入口。

2. 如何自定义指定偏好的Shell

有两种常用方式可以指定你想要的Shell:

方式一:在脚本中直接调用目标Shell

比如要使用bash,可以把脚本内容用bash -c包裹:

run python:
  image: python:3.10
  script:
    - |
      bash -c '
        cd "src"
        pip install -r ../requirements.txt
        ls -l
      '

方式二:通过Job配置覆盖入口点或指定Shell变量

你可以在Job中设置entrypoint,直接指定用目标Shell作为入口:

run python:
  image: python:3.10
  entrypoint: ["bash", "-c"]
  script:
    - |
      cd "src"
      pip install -r ../requirements.txt
      ls -l

或者通过variables指定全局Shell变量:

run python:
  image: python:3.10
  variables:
    SHELL: /bin/bash
  script:
    - |
      cd "src"
      pip install -r ../requirements.txt
      ls -l

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 10:10:14