`after_script`总是被执行,即使是被取消的工作?

时间:2018-06-11 15:23:01

标签: gitlab gitlab-ci

documentation并不清楚是否针对取消的工作执行了after_script

  

after_script用于定义将在所有作业(包括失败的作业)之后运行的命令。

我在after_script进行了潜在的重要清理,虽然取消的工作很少见,但我想知道我的清理工作确实会发生。

1 个答案:

答案 0 :(得分:3)

不,我进行了一些测试,这是我展出的行为:

after_script:
  - echo "This is not executed when a job is cancelled."
  - echo "A failing command, like this one, doesn't fail the job." && false
  - echo "This is not executed because the previous command failed."

1。取消作业时不执行after_script

gitlab.com上有一个open issue,所以如果这对你有影响,那就去那边做一些噪音。

2。如果after_script中的命令失败,则其余命令不会执行

这很容易解决:

after_script:
  - potentially failing command || true
  - next command

potentially failing command替换为您的命令,无论next command是通过还是失败,potentially failing command都会执行。

有人可能会说这种行为实际上是需要的,因为它为用户提供了一些灵活性,但它可能与某些人违反直觉。