在 gitlab ci pipeline / python 3 alpine image 中找不到 sphinx-build 命令

sphinx-build command not found in gitlab ci pipeline / python 3 alpine image

我想指定一个创建 sphinx html 文档的 GitLab 作业。

我正在使用 Python 3 alpine 图像(无法具体说明是哪个)。

我的 .gitlab-ci.yml 中的构建阶段如下所示:

pages:
  stage: build
  tags: 
  - buildtag
  script:
  - pip install -U sphinx
  - sphinx-build -b html docs/ public/
  only:
  - master

然而,管道失败:sphinx-build: command not found。 (make html 的相同错误)

根据This Tutorial,我的.gitlab-ci.yml应该或多或少是正确的。

我做错了什么?这个问题与我使用的 alpine 镜像有关吗?

最有可能的原因是 $PATH 不包含 sphinx-build

的路径

TL;DR 尝试使用 command

试试这个:

pages:
  stage: build
  tags: 
  - buildtag
  script:
  - pip install -U sphinx
  - command sphinx-build -b html docs/ public/
  only:
  - master

说明

GitLab 运行人运行不同的方式

由于 GitLab CI 使用 runnersrunner 的 shell 配置文件可能与常用的不同。

因此,您的 运行ner 可以在未声明 [​​=11=] 的情况下配置到包含 sphinx-build

的目录

Zsh/Bash 启动文件加载顺序(.bashrc、.zshrc 等)

this explanation:

The issue is that Bash sources from a different file based on what kind of shell it thinks it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive login shell” it reads from the first of .bash_profile, .bash_login and .profile (only). There is no sane reason why this should be so; it’s just historical.

command 是什么意思?

由于我们不知道sphinx-build的安装路径,您可以使用如下命令:whichtype

根据这个很好的答案(shell - Why not use "which"? What to use then? - Unix & Linux Stack Exchange,作者建议使用 command <name>,或 $(command -v <name>)

命令pip install -U sphinx成功了吗? (您应该能够从 CI 作业日志中看出这一点。)

如果是这样,您可能需要指定 sphinx-build 的完整路径,正如 Yasen 所说。

如果没有成功,您应该对 Sphinx 的安装进行故障排除。

正如@Yasen 正确指出的那样,sphinx-build 的路径未包含在 $PATH 中。但是,在 sphinx-build 之前添加 command 并没有解决我的问题。

无论如何,我在运行器日志中找到了解决方案:pip install -U sphinx 的输出产生了以下警告:

WARNING: The scripts sphinx-apidoc, sphinx-autogen, sphinx-build and sphinx-quickstart are installed in 'some/path' which is not on PATH.

所以我将 export PATH="some/path" 添加到 .gitlab-ci.yml 中的脚本步骤:

script:
  - pip install -U sphinx
  - export PATH="some/path"
  - sphinx-build -b html docs/ public/