我正在尝试遵循Github使用github操作测试我的构建的示例,然后压缩测试结果并将其作为工件上传。https://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts#uploading-build-and-test-artifacts
但是,当我的测试失败时,我不知道该怎么做。这就是我的行动。当我的测试通过一切工作正常时,我的结果将被压缩并导出为工件,但是如果我的测试失败,它将停止作业中的其余步骤,因此我的结果永远不会被发布。

我尝试添加continue-on-error: true https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error
这使它在失败后继续,并上传我的测试结果。但是,即使我的测试步骤失败了,作业也被标记为已通过。有没有办法让它上传我的工件,即使其中一个步骤失败了,同时仍然将整个作业标记为失败?
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Test App
run: ./gradlew test
- name: Archive Rest Results
uses: actions/upload-artifact@v1
with:
name: test-results
path: app/build/reports/tests发布于 2019-11-14 22:42:49
您可以添加
if: always()设置为您的步骤,以便即使上一步失败也能运行https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#job-status-check-functions
因此,对于单个步骤,它将如下所示:
steps:
- name: Build App
run: ./build.sh
- name: Archive Test Results
if: always()
uses: actions/upload-artifact@v1
with:
name: test-results
path: app/build或者您可以将其添加到作业中:
jobs:
job1:
job2:
needs: job1
job3:
if: always()
needs: [job1, job2]发布于 2021-11-20 16:55:21
另外,你也可以添加continue-on-error: true。看起来像
- name: Job fail
continue-on-error: true
run |
exit 1
- name: Next job
run |
echo Hello在here上阅读更多内容。
发布于 2021-09-13 09:00:32
插件:如果您有以下情况,请使用。2个步骤,即build > deploy,在某些情况下,即带有输入参数的workflow_dispatch,您可能希望跳过build,继续使用deploy。同时,您可能希望在build失败时跳过deploy。
从逻辑上讲,这应该类似于skipped or not failed as deploy conditional。
if: always()将不工作,因为它将始终触发deploy,即使build失败。
解决方案非常简单:
if: ${{ !failure() }}
注意,在if:中否定时不能跳过括号,因为它会报告语法错误。
https://stackoverflow.com/questions/58858429
复制相似问题