是否可以允许CI / CD作业中的脚本失败?

问题描述 投票:0回答:1

整个职位can be allowed to fail

job1:
  stage: test
  script:
    - execute_script_that_will_fail
  allow_failure: true

是否有可能在一系列脚本中有一个允许失败的(和其他 - 不是)?

job1:
  stage: test
  script:
    - execute_script_that_MAY_fail_and_should_be_marked_somehow_in_this_config_as_such
    - execute_script_that_MUST_NOT_fail

基本原理是可能存在相关的脚本,应该组合在一起并且是顺序的,并且只允许其中一些脚本失败。

一个例子可能是具有build(必须不会失败)的docker部署,容器的stop(如果容器未运行可能会失败)和run(必须不会失败)。

我目前的解决方法是将其拆分为单独的工作,但这是一个丑陋的黑客:

stages:
  - one
  - two
  - three

one:
  stage: one
  script:
    - execute_script_that_MUST_NOT_fail

two:
  stage: two
  script:
    - execute_script_that_MAY_fail
  allow_failure: true

three:
  stage: three
  script:
    - execute_script_that_MUST_NOT_fail
gitlab gitlab-ci
1个回答
0
投票

如果作业中的任何脚本步骤返回失败状态,则作业将失败。因此,您需要防止这种情况发生,最简单的方法是将|| true添加到该步骤(或者某些日志记录,如@ahogen在评论中建议):

job1:
  stage: test
  script:
    - execute_script_that_MAY_fail || true
    - execute_script_that_MUST_NOT_fail
© www.soinside.com 2019 - 2024. All rights reserved.