continuous-integration - 如何在 1 个作业中定义 2 个具有不同 when

我尝试制作使用 gradle 构建代码的 CI。问题是,当构建失败时,它没有上传我的测试报告,这是我稍后调试所需要的。

build:
  stage: build
  script:
    - ./gradlew build --info
  artifacts:
    paths:
      - build/install/<app_name>/*
      - build/reports/*
    expire_in: 7 days
    reports:
      junit: build/test-results/test/TEST-*.xml

作为 gitlab-ci 默认,它只在构建成功时上传工件。但是我需要始终上传测试报告,并且只有在构建成功时才上传构建文件。我可以使用 always 和 on_success 但我不确定我是否可以在 1 项工作的条件下分离这 2 个工件。

最佳答案

您可以添加一个阶段,用于在发生故障时收集报告。
在下面的示例中,我添加了 build-reports 阶段和 when: on_failure 并且它负责收集日志和报告。

stages:
  - build
  - build-reports


build:
  stage: build
  allow_failure: false
  artifacts:
    paths:
    - report.txt
    - output.txt
    expire_in: 1 week
  script:
    - echo "Reports:" $(date) > report.txt
    - echo "Output:" $(date) > output.txt

Build-Reports:
  stage: build-reports
  when: on_failure
  artifacts:
    name: Build reports
    paths:
    - report.txt
    expire_in: 1 week
  script:
    - echo "Build Failed" >> report.txt

成功构建的管道输出:(构建阶段的工件包含:report.txtoutput.txt )

失败构建的管道输出(Build-Reports 阶段的工件包含:report.txt)

关于continuous-integration - 如何在 1 个作业中定义 2 个具有不同 when 条件的工件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55963183/

相关文章:

php - 电子商务 : how to display custom success notice

http - Telegram: Bad Request: failed to get HTTP U

amazon-dynamodb - AWS DynamoDB 中没有任何注释的普通 POJO

angular - 重新分配通过异步管道使用的 Observable

c# - 为什么 IServerStreamWriter 不发送通知响应?

java - @PathVariable 在路径变量 {} 前附加 "/"时出现 404 错误

azure-active-directory - Azure B2C 访问 token 缺少 ten

python-3.x - aiohttp异步请求的任务异常

reactjs - VSCode 不会在 typescript 中导入 组件

javascript - 使用 cheerio 在两个标签之间进行网页抓取