相同Docker镜像与YAML在两台Ubuntu机器GitLab CI执行差异原因排查
问题:GitLab CI/CD生成Doxygen文档本地正常,服务器执行失败
本地Ubuntu机器上执行GitLab CI/CD生成Doxygen文档流程正常,但同版本Ubuntu服务器上执行失败,报错error: configuration file sh not found!,两台机器使用完全相同的.gitlab-ci.yaml配置。
本地执行日志
Getting source from Git repository 00:01 Fetching changes with git depth set to 20... Reinitialized existing Git repository in /builds/Piotr/doxygen-test/.git/ Checking out cd74c1b2 as detached HEAD (ref is DOXYGEN-MASTER)... Removing warn.log Skipping Git submodules setup Executing "step_script" stage of the job script 00:06 Using docker image sha256:e6199347aa9ac5396eb43c2f808da322206fb532a7523d55710f2e4b6d23b27a for gul-doxygen-noentry:latest ... $ echo "executing the doxygen" executing the doxygen $ doxygen ./Doxyfile
服务器执行日志
Preparing environment 00:01 Running on runner-a-9fmufr-project-79-concurrent-0 via srvlnx01... Getting source from Git repository 00:02 Fetching changes with git depth set to 50... Reinitialized existing Git repository in /builds/Piotr/doxygen-test/.git/ Checking out 5ca96c41 as detached HEAD (ref is DOXYGEN-MASTER)... Removing Dockerfile Skipping Git submodules setup Executing "step_script" stage of the job script 00:02 Using docker image sha256:02b28832c626ab59f98b137ac9a5a417888c6fdb997ec845a208f855493c9d9a for gul-doxygen:latest ... error: configuration file sh not found!
共用的.gitlab-ci.yaml配置
image: name: gul-doxygen:latest entrypoint: [""] pages: script: - echo "executing the doxygen" - doxygen ./Doxyfile - ls -l ../documentation - mv ../documentation/html/ public/ artifacts: paths: - public only: - DOXYGEN-MASTER
差异原因分析
- 镜像实际使用不一致:本地日志显示使用的是
gul-doxygen-noentry:latest镜像,而服务器使用的是gul-doxygen:latest镜像,二者的Entrypoint配置存在本质差异。 - Entrypoint触发命令冲突:
gul-doxygen:latest镜像的默认Entrypoint被设置为doxygen,此时即使CI配置中指定entrypoint: [""],部分环境下可能未正确覆盖默认配置,导致GitLab Runner尝试用doxygen去执行shell脚本命令——即把sh作为参数传给doxygen,触发configuration file sh not found!错误。
解决步骤
- 统一镜像版本:将CI配置中的镜像替换为本地验证有效的
gul-doxygen-noentry:latest,确保服务器和本地使用完全一致的镜像:image: name: gul-doxygen-noentry:latest entrypoint: [""] - 修复镜像Entrypoint配置:如果必须使用
gul-doxygen:latest,先在服务器上查看镜像的默认Entrypoint:
若Entrypoint为docker inspect gul-doxygen:latest | grep -A 5 "Entrypoint"doxygen,则修改CI配置的entrypoint为shell解释器,确保脚本能正常执行:image: name: gul-doxygen:latest entrypoint: ["/bin/sh", "-c"] - 清理服务器镜像缓存:服务器可能缓存了旧版本的
gul-doxygen:latest,执行以下命令拉取最新镜像:docker pull gul-doxygen:latest
内容的提问来源于stack exchange,提问作者0___________
相关产品推荐
相关产品推荐

