[英]How to run a github-actions step, even if the previous step fails, while still failing the job
[英]How to run a script at the end of a job, even if the job was cancelled?
这是我目前在 GitHub 上使用的工作流程
name: Windows10 - CI
on: [ push ]
jobs:
run-test:
runs-on: [ self-hosted, windows, DO ]
steps:
- uses: actions/checkout@v2
with:
clean: false
- name: Run nds2 CI - Sanity Test
if: github.ref == 'refs/heads/master'
run: cd c:\actions-runner\_work\nds2\nds2 ; python3 ci_host.py --master
- name: Run nds2 CI - Build Installer
if: github.ref != 'refs/heads/master'
run: cd c:\actions-runner\_work\nds2\nds2 ; python3 ci_host.py
我有一台 windows 10 计算机,它使用 GitHub 运行器监听传入的作业。 在传入作业时,如果对主分支进行推送,则脚本 ci_host.py 将使用“--master”标志运行,该标志会启动 VM 并在其上运行多个测试。 最终,在测试结束时,脚本会将 VM 恢复到预先配置的快照。
所以基本上我想要实现的是,当通过 GitHub 操作 web 接口取消作业时,处理测试的脚本在作业中被取消并且没有机会将 VM 恢复到之前清洁 state(快照)。
即使作业被取消,如何运行将在工作流结束时运行的脚本? 所以无论发生什么,我的虚拟机都可以恢复到干净的 state
在此先感谢您的帮助:)
您可以使用作业状态检查功能来执行一个步骤,具体取决于作业之前(或未)发生的情况:
success
:当前面的步骤都没有失败或被取消时返回true
。
always
:始终返回true
,即使取消也是如此。 当严重故障阻止任务运行时,作业或步骤将不会运行。 例如,如果获取源失败。
cancelled
:如果工作流被取消,则返回true
。
failure
:当作业的任何先前步骤失败时返回true
。
使用示例:
steps:
...
- name: Execute if the job succeeded
if: ${{ success() }}
- name: Execute if the job failed
if: ${{ failure() }}
- name: Execute if the job was cancelled
if: ${{ cancelled() }}
- name: Always execute
if: ${{ always() }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.