簡體   English   中英

Docker 構建失敗但 Gitlab-CI 報告成功(誤報)

[英]Docker Build fails but Gitlab-CI reports succeeds(False positive)

我有一個 Gitlab 管道,它從 Dockerfile 構建我的 Docker 圖像,但是當“docker build”命令失敗時,管道仍然報告成功。

build:
  stage: build
  script:
    - docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL .

我在我的 Dockerfile 中添加了一個錯誤,所以我可以引發一個錯誤:

FROM ubuntu:20.04   
RUN not_a_real_command_that_should_fail

管道運行:

Running with gitlab-runner 14.0.1 (c1edb478)
  on ******* Cy33WtLD
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on **********...
Getting source from Git repository
00:04
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/gitlab-runner/builds/Cy33WtLD/0/dockerfile/.git/
Checking out 999a815d as fix_pipeline_status...
git-lfs/2.13.2 (GitHub; windows amd64; go 1.14.13; git fc664697)
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:03
$ docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL .
#1 [internal] load build definition from Dockerfile
#1 sha256:c544637cbaca3e93c2a8a8c00efd4f81ee45b1abd410d971af12de8dae21e8ea
#1 transferring dockerfile: 3.04kB done
#1 DONE 0.0s
#2 [internal] load .dockerignore
#2 sha256:ab745a167b371ba5e9380063cb278a7792a5838550b89f02f35d7f6a583fb548
#2 transferring context: 2B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/ubuntu:20.04
#3 sha256:8e67b796a66f85f06793e026943184e32d365c77929e94d2ac98b34a1e1cb30e
#3 DONE 0.6s
#4 [ 1/17] FROM docker.io/library/ubuntu:20.04@sha256:9d6a8699fb5c9c39cf08a0871bd6219f0400981c570894cd8cbea30d3424a31f
#4 sha256:c8b7f784dc481f981cf0bc39c4d4e60a54a355d96ca108a13ffffa3bfa047067
#4 CACHED
#20 [internal] load build context
#20 sha256:d12ef8e847404a2cc9437d8099f4b73f215c48eb92002e759a5f264989ae3ace
#20 transferring context: 92B 0.0s done
#20 DONE 0.0s
#5 [ 2/17] RUN not_a_real_command_that_should_fail
#5 sha256:724c85340f260555ab116f9064ba3c7a2c16fe0af059ef5226df31545b30ddb6
#5 0.485 /bin/sh: 1: not_a_real_command_that_should_fail: not found
#5 ERROR: executor failed running [/bin/sh -c not_a_real_command_that_should_fail]: exit code: 127
------
 > [ 2/17] RUN not_a_real_command_that_should_fail:
------
executor failed running [/bin/sh -c not_a_real_command_that_should_fail]: exit code: 127
Cleaning up file based variables
00:01
Job succeeded

退出代碼是 127,我添加了一個 -after_stage 步驟來打印返回代碼“echo $?” 並得到“真實”的結果。 看起來這應該足以讓命令觸發管道中的故障。 如果重要的話,gitlab-runner 是 Windows 機器上的 shell 執行程序。

有什么建議么?

1 - Gitlab 問題

13.1.1 之前的 gitlab 運行器版本存在錯誤:

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/26347

FF_USE_LEGACY_KUBE.NETES_EXECUTION_STRATEGY設置為False時,作業總是成功的

解決方案似乎正在更新。

2 - 腳本問題

嘗試在錯誤時強制退出 1

build:
  stage: build
  script:
    - docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL . || exit 1

編輯 1

默認情況下,Powershell 繼續執行。

您可以設置這些變量:

job:
  stage: build
  variables: 
    ErrorActionPreference: stop 
  script:
    - docker build --no-cache -t $CI_REGISTRY/dockerfile:$CONTAINER_LABEL . 

詳情請看github這個issue:

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4683

將管道移動到 Ubuntu 機器上的 gitlab-runner 后,管道按預期失敗。 假設 Windows-Powershell 退出代碼未正確觸發

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM