![](/img/trans.png)
[英]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.