无法从Gitlab CI中的Shell脚本获取输出

时间:2019-09-20 11:03:33

标签: shell gitlab

我在窗户上设置了一个gitlab运行程序。我有一个build.sh脚本,仅在其中显示“ Hello world”。我在gitlab-ci.yml文件中提供了以下行:

build:
    stage: build
    script:
        - ./build.sh

运行程序执行此作业,但不打印我在build.sh文件中提到的echo命令。但是,如果我将扩展名更改为.bat,它将起作用并显示输出。 gitlab-runner被设置用于shell。可能是什么原因?还是我缺少什么?

1 个答案:

答案 0 :(得分:1)

GitLab将输出任何最终写入STDOUT或STDERR的内容。不看整个脚本就很难说发生了什么,但我想您实际上并没有在STDOUT上回声。这就是为什么输出未最终出现在CI输出中的原因。

为了测试这一点,我在GitLab.com上创建了一个测试项目。测试中的一个不同之处是我的CI YAML脚本命令是sh build.sh。这是因为该脚本不可执行,因此无法使用./build.sh执行。

builds.sh文件:

#!/bin/bash

echo "This is output from build.sh"

.gitlab-ci.yml文件:

build:
  stage: build
  script:
    - sh build.sh

构建输出:

Running with gitlab-runner 12.3.0-rc1 (afb9fab4)
  on docker-auto-scale 72989761
...
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/dblessing/ci-output-test/.git/
Created fresh repository.
Checking out cfe8a4ee as master...

Skipping Git submodules setup

$ sh build.sh
This is output from build.sh
Job succeeded