你如何查看在 gitlab-runner exec 期间创建的日志?

How do you view a log created during gitlab-runner exec?

我正在使用 gitlab-runner exec 测试 GitLab CI 管道。在执行脚本期间,Boost 运行 出现错误,并创建了一个日志文件。我想查看此日志文件,但我不知道如何查看。

.gitlab-ci.yml 在项目目录中:

image: alpine

variables:
  GIT_SUBMODULE_STRATEGY: recursive

build:
  script:
  - apk add cmake
  - cd include/boost
  - sh bootstrap.sh

我在我的机器上测试这个:

sudo gitlab-runner exec docker build --timeout 3600

输出的最后几行:

Building Boost.Build engine with toolset ... 
Failed to build Boost.Build build engine
Consult 'bootstrap.log' for more details
ERROR: Job failed: exit code 1
FATAL: exit code 1    

bootstrap.log是我想看的

- cat bootstrap.log 附加到 .gitlab-ci.yml 不会输出文件内容,因为运行器在此行之前退出。我试着查看过去带有 sudo docker ps -a 的容器,但这并没有显示 GitLab Runner 使用的容器。如何打开 bootstrap.log?

您可以为日志声明一个工件:

image: alpine

variables:
  GIT_SUBMODULE_STRATEGY: recursive

build:
  script:
    - apk add cmake
    - cd include/boost
    - sh bootstrap.sh

  artifacts:
    when: on_failure
    paths:
      - include/boost/bootstrap.log

之后,您将能够通过网络界面下载日志文件。

请注意,使用 when: on_failure 将确保仅在构建失败时才收集 bootstrap.log,在成功构建时节省磁盘 space。