github - 仅当上一步已运行时才运行 GitHub Actions 步骤
问题描述
我在 GitHub 操作中设置了一个工作流来运行我的测试并创建测试覆盖率的工件。我的 YAML 文件的精简版本如下所示:
name: Build
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Other steps here
- name: Build app
- name: Run tests
- name: Create artifact of test coverage
# Other steps here
问题是当测试失败时没有创建工件。
我从文档中弄清楚了if: always()
条件,但这也会导致当我的步骤失败时运行此步骤。我不希望这种情况发生,因为在这种情况下没有什么可以存档的。Build app
如果上一步已经运行(成功或失败),我如何才能运行这一步?
解决方案
尝试检查success()
OR failure()
。
name: Build
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Other steps here
- name: Build app
- name: Run tests
- name: Create artifact of test coverage
if: success() || failure()
# Other steps here
或者,创建退出代码的步骤输出,您可以在以后的步骤中检查它。例如:
- name: Build app
id: build
run: |
<build command>
echo ::set-output name=exit_code::$?
- name: Run tests
- name: Create artifact of test coverage
if: steps.build.outputs.exit_code == 0
推荐阅读
- c# - 如何在 dotCover 覆盖分析期间忽略单元测试?
- docker - 挂载 USB:docker 中的权限被拒绝
- angular - 防止 Angular 重新渲染从 NgRx 减速器中复制的组件
- html - 为什么v-html不渲染html
- asynchronous - 为什么我无法捕获异常?
- kdb - 为什么在 kdb 中强制为左连接键入查找表
- python - 使用 selenium 在网页上的两个文本值之间选择元素
- reactjs - 从功能组件中公开一个功能 - React
- mysql - 如何在一条记录中选择表 A 的数据,表 B 中的其他列填充表 C 中的数据
- kotlin - 如何在 Kotlin 的 onResume 中使用 savedInstanceState?