You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

流水线Test阶段Warning完成但API显示Failed,如何获取正确状态?

问题描述

我们的流水线包含以下阶段:

  • download:根据版本号从artifactory下载项目压缩包
  • build:在runner上编译并部署下载的压缩包
  • test:执行测试并上传结果

执行流水线时,有时test阶段会以Warning状态完成,但调用API查询该阶段状态时,返回的却是failed。请问有没有办法(或API参数)能获取这个阶段的真实Warning状态?

以下是触发Warning状态的示例YAML配置:

stages:
  - download
  - build
  - test

download:
  stage: download
  script:
    - echo "===== Download starts ====="
    - echo "===== Download Ends ====="
  tags:
    - linux
build:
  stage: build
  script:
    - echo "===== Build starts ====="
    - echo "===== Build Ends ====="
  tags:
    - linux
test:
  stage: test
  script:
    - echo "===== Test starts ====="
    - echo "===== Test Ends ====="
    - exit 2;
  tags:
    - linux
  allow_failure:
    exit_codes:
      - 2
解决方案

要获取该阶段的真实Warning状态,你需要结合API返回的多个字段综合判断:

  • API返回的status字段会显示为failed,这是因为test job的实际退出码是非0的;
  • 同时检查allow_failure字段:如果该字段为true(或者配置了匹配当前退出码的allow_failure.exit_codes),且status为failed,则说明这个job是以Warning状态完成的。

比如调用GET /projects/:id/jobs/:job_id查询该test job详情时,返回结果会包含类似以下的关键字段:

{
  "status": "failed",
  "allow_failure": true,
  "exit_code": 2
}

通过这三个字段的组合,就能准确判断该job实际是Warning状态——虽然执行失败,但由于配置了允许该失败不阻断流水线,所以界面上显示为Warning。

如果是查询流水线的阶段汇总数据,你需要遍历阶段下的所有job,通过上述字段组合推导阶段的真实状态,因为阶段状态是由其下所有job的状态聚合而来的。

内容的提问来源于stack exchange,提问作者Yogesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 18:35:02