我已经在GitHub Action 中设置了工作流程来运行测试并创建测试覆盖范围的工件。我的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
问题是测试失败时不会创建工件。
我从docs中了解了
if: always()
条件,但是当我的Build app
步骤失败时,这也将导致此步骤运行。我不希望发生这种情况,因为在这种情况下没有可存档的内容。如果上一步已经运行(成功或失败),如何才能执行此步骤?
最佳答案
尝试检查success()
或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
关于github - 仅在上一步已运行的情况下运行GitHub Actions步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60453924/