Gitlab CI作业运行良好,但总是在退出代码为1时崩溃



I',尝试在Gitlab CI中使用hadolint将dockerfiles与我的.Gitlab-CI.yml文件中的这个片段进行整理:

lint-dockerfile:
image: hadolint/hadolint:latest-debian
stage: verify
script:
- mkdir -p reports
- hadolint -f gitlab_codeclimate Dockerfile > reports/hadolint-$(md5sum Dockerfile | cut -d" " -f1).json
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
codequality:
- "reports/*"
paths:
- "reports/*"

这以前工作得很好,但一周前(我没有任何改变(,我的管道一直在ERROR: Job failed: exit code 1上崩溃。

作业的完整日志输出:

Running with gitlab-runner 14.0.0-rc1 (19d2d239)
on docker-auto-scale 72989761
feature flags: FF_SKIP_DOCKER_MACHINE_PROVISION_ON_CREATION_FAILURE:true
Resolving secrets 00:00
Preparing the "docker+machine" executor 00:14
Using Docker executor with image hadolint/hadolint:latest-debian ...
Pulling docker image hadolint/hadolint:latest-debian ...
Using docker image sha256:7caf5ee484b575ecd32219eb6f2a7a114180c41f4d8671c1f8e8d579b53d9f18 for hadolint/hadolint:latest-debian with digest hadolint/hadolint@sha256:2c06786c0d389715dae465c9556582ed6b1c38e1312b9a6926e7916dc4a9c89e ...
Preparing environment 00:01
Running on runner-72989761-project-26715289-concurrent-0 via runner-72989761-srm-1624273099-5f23871c...
Getting source from Git repository 00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/sommerfeld.sebastian/docker-vagrant/.git/
Created fresh repository.
Checking out f664890e as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:01
Using docker image sha256:7caf5ee484b575ecd32219eb6f2a7a114180c41f4d8671c1f8e8d579b53d9f18 for hadolint/hadolint:latest-debian with digest hadolint/hadolint@sha256:2c06786c0d389715dae465c9556582ed6b1c38e1312b9a6926e7916dc4a9c89e ...
$ mkdir -p reports
$ hadolint -f gitlab_codeclimate Dockerfile > reports/hadolint-$(md5sum Dockerfile | cut -d" " -f1).json
Uploading artifacts for failed job 00:03
Uploading artifacts...
reports/*: found 1 matching files and directories  
Uploading artifacts as "archive" to coordinator... ok  id=1363188460 responseStatus=201 Created token=vNM5xQ1Z
Uploading artifacts...
reports/*: found 1 matching files and directories  
Uploading artifacts as "codequality" to coordinator... ok  id=1363188460 responseStatus=201 Created token=vNM5xQ1Z
Cleaning up file based variables 00:01
ERROR: Job failed: exit code 1

我不知道为什么我的构建突然中断。我使用image: docker:stable作为我的整个.gitlab-ci.ymnl文件的图像。

有什么想法吗?

结束这个问题。该问题是行为上的意外变化,可能是由此处使用的hadolint图像的更新引起的。

事实上,这项工作之所以失败,是因为短工决定这么做。对于任何想成功完成这项工作的人来说,这里有一个小技巧:

hadolint -f gitlab_codeclimate Dockerfile > reports/hadolint-$(md5sum Dockerfile | cut -d" " -f1).json || true

给定的命令将强制退出代码为正,无论发生什么情况。

正如@Sebastian Sommerfeld所指出的,另一种选择是使用allow_failure:true,这本质上允许脚本失败,然后将在管道概述中标记。这种方法的唯一缺点是脚本执行在失败时被中断,并且不能执行进一步的命令。

最新更新