I'm trying to follow an example Github has for testing my build with github actions, and then compressing the test results and uploading them as an artifact. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/persisting-workflow-data-using-artifacts#uploading-build-and-test-artifacts
I'm having trouble with what to do when my tests fail though. This is my action. When my tests pass everything works great, my results are zipped an exported as an artifact, but if my tests fail, it stops the rest of the steps in the job, so my results never get published.
I tried adding the 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
This makes it continue after it fails and uploads my test results. but then the job is marked as passed, even though my test step failed. Is there some way to have it upload my artifact even if a step fails, while still marking the overall job as failed?
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
Re-running all the jobs in a workflowIn the left sidebar, click the workflow you want to see. From the list of workflow runs, click the name of the run to see the workflow run summary. In the upper-right corner of the workflow, use the Re-run jobs drop-down menu, and select Re-run all jobs.
Only jobs can run in parallel, but steps always run sequentially.
On GitHub.com, navigate to the main page of the repository. Under your repository name, click Actions. In the left sidebar, click the workflow you want to run. Above the list of workflow runs, select Run workflow.
To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .
While Github Actions doesn’t provide a way to re-run just the failed jobs out of the box, let’s build something on our own. 1. Set up a step to get the current timestamp 2. Name a cache container using the above timestamp 3. Restore the previous result 4. Set up a condition for further steps 5. Save the result on success
GitHub Actions: Skipping a step without failing | An independent mind… I wanted to have a GitHub Action step run that might fail, but if it failed the rest of the steps should still execute and the overall run should be treated as a success. Skip to primary navigation Skip to content Skip to footer An independent mind... Portfolio Posts Categories
Follow these steps to manually trigger a workflow run. Write access to the repository is required to perform these steps. On GitHub, navigate to the main page of the repository. Under your repository name, click Actions . In the left sidebar, click the workflow you want to run. Above the list of workflow runs, select Run workflow .
Most GitHub events are triggered by more than one type of activity. For example, the label is triggered when a label is created, edited, or deleted. The types keyword enables you to narrow down activity that causes the workflow to run. When only one activity type triggers a webhook event, the types keyword is unnecessary.
You can add
if: always()
to your step to have it run even if a previous step fails https://help.github.com/en/actions/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#job-status-check-functions
so for a single step it would look like this:
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
Or you can add it to a job:
jobs: job1: job2: needs: job1 job3: if: always() needs: [job1, job2]
Other way, you can add continue-on-error: true
. Look like
- name: Job fail continue-on-error: true run | exit 1 - name: Next job run | echo Hello
Read more in here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With