在gitlab ci管道/ python 3高山图像中找不到sphinx-build命令

时间:2020-04-09 12:33:54

标签: python gitlab gitlab-ci python-sphinx alpine

我想指定一个创建狮身人面像html文档的GitLab作业。

我正在使用Python 3高山图像(无法确切指定哪个图像)。

.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应该或多或少正确。

我在做什么错?这个问题与我使用的高山图像有关吗?

3 个答案:

答案 0 :(得分:2)

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

无论如何,我在运行日志中找到了解决方案: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/

答案 1 :(得分:1)

最可能的原因是$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使用runners,因此runner的shell配置文件可能与常用的不同。

因此,您的运行程序可能在没有声明$PATH的情况下配置到包含sphinx-build的目录中

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

请参见this explanation

问题在于,Bash根据其认为所在的外壳类型从不同文件中获取资源。对于“交互式非登录外壳”,其读取为.bashrc,而对于“交互式登录外壳”,其读取为来自.bash_profile,.bash_login和.profile的 first (仅限)。没有理智的理由应该如此。这只是历史。

command是什么意思?

由于我们不知道sphinx-build的安装路径,因此您可以使用诸如whichtype等命令。

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

答案 2 :(得分:1)

命令pip install -U sphinx是否成功? (您应该能够从CI作业日志中得知。)

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

如果未成功,则应该对Sphinx的安装进行故障排除。