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
(必须失败),stop
的容器(如果容器未运行可能会失败)和run
的docker部署。 (一定不能失败)。
我当前的解决方法是将其拆分为单独的作业,但这是一个丑陋的骇客:
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
答案 0 :(得分:0)
如果作业中的任何脚本步骤返回失败状态,则该作业将失败。因此,您需要防止这种情况的发生,最简单的方法是在该步骤中添加|| true
(或在@ahogen中在注释中建议一些日志记录):
job1:
stage: test
script:
- execute_script_that_MAY_fail || true
- execute_script_that_MUST_NOT_fail