# Stage to pull and push image
job1:
stage: job1
allow_failure: true
script:
# Pull image and save success
- docker pull ${SOURCE_IMAGEURI}:${TAG}
...
- docker tag ${SOURCE_IMAGEURI}:${TAG} ${TARGET_IMAGEURI}:${TAG}
# Job might fail here due to not enough permissions which is what I want to happen
- docker push ${TARGET_IMAGEURI}:${TAG}
- echo "Error Message" > curldata.txt
artifacts:
when: always
paths:
- curldata.txtjob2:
stage: job2
script:
# Do something with the error that happened in job1
when: always
dependencies:
- job1因此,上面是拉动和推送图像的作业的一部分。有时,由于缺乏权限,作为安全步骤,镜像将无法推送。我如何捕获发生的错误,以便将工件发送到下一个反馈作业。此作业会将信息发送给用户,以便他/她知道他们没有足够的权限。
发布于 2021-11-18 19:56:47
您可以将命令的(stderr)输出tee到一个文件中,并对该文件进行工件处理。
script:
# ...
# show output of the command and store stderr to text file
- docker push ${TARGET_IMAGEURI}:${TAG} 2> >(tee stderr.txt)
artifacts:
paths:
- stderr.txt
when: always如果你需要一些逻辑在错误之后发生,你可以使用and/或逻辑门。
docker push ${TARGET_IMAGEURI}:${TAG} || echo "do this if it fails" > error.txt && exit 1关于健壮的error handling in bash还有更多要说的,但这些都是您可以使用的基本概念。
https://stackoverflow.com/questions/70024509
复制相似问题