.gitlab-ci.yml after_script部分:如何判断任务成功还是失败? [英] .gitlab-ci.yml after_script section: how can I tell whether the task succeeded or failed?

查看:1211
本文介绍了.gitlab-ci.yml after_script部分:如何判断任务成功还是失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Gitlab CI ,因此一直在努力一个相当复杂的 .gitlab-ci.yml 文件.该文件具有after_script节,该节在主要任务完成或主要任务因某种原因失败时运行.问题:我需要根据主要任务是成功还是失败进行不同的清理,但是我找不到任何

I'm using Gitlab CI, and so have been working on a fairly complex .gitlab-ci.yml file. The file has an after_script section which runs when the main task is complete, or the main task has failed somehow. Problem: I need to do different cleanup based on whether the main task succeeded or failed, but I can't find any Gitlab CI variable that indicates the result of the main task.

如何在after_script部分中判断主要任务是成功还是失败?

How can I tell, inside the after_script section, whether the main task has succeeded or failed?

推荐答案

我建议您定义另一个阶段,并使用

Instead of determining whether or not the task succeeded or failed in the after_script, I would suggest defining another stage, and using the when syntax, where you can use when: on_failure or when: on_success.

文档中的示例:

stages:
- build
- cleanup_build
- test
- deploy
- cleanup

build_job:
  stage: build
  script:
  - make build

cleanup_build_job:
  stage: cleanup_build
  script:
  - cleanup build when failed
  when: on_failure

test_job:
  stage: test
  script:
  - make test

deploy_job:
  stage: deploy
  script:
  - make deploy
  when: manual

cleanup_job:
  stage: cleanup
  script:
  - cleanup after jobs
  when: always

这篇关于.gitlab-ci.yml after_script部分:如何判断任务成功还是失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆