-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
This is a sub-issue of #1376 and goes a small way to supporting the functionality described there. This issue is focused solely on running Steps inside a Task when prior steps (within the same Task) have failed. This issue specifically does not deal with running whole Tasks when previous Tasks have failed.
Motivating Use Cases
- A unit test step fails but a subsequent step in the same Task should upload the results to a bucket regardless of that failure.
- A Pull Request pipeline resource should update a PR with a comment reflecting the status of a failed build. The build happens in one step and then the PR resource could inject a step at the end which runs regardless of the error and knows how to update github/gitlab/etc with the status comment.
Current Support
There currently isn't support for running a subsequent Step if a prior one has already failed in the same Task.
Suggested User-Facing Change
Add a field to the Step type that is named something like ignorePreviousStepErrors. It defaults to false. Setting this field to true will tell that Step to run regardless of whether prior steps in the same Task failed.
Example YAML:
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
generateName: test-and-upload-to-gcs-
spec:
taskSpec:
steps:
- name: test
image: node-run-tests
command: ['npm']
args: ['run', 'tests']
- name: publish-npm-package
image: node-publish-package
command: ['npm']
args: ['run', 'tests']
- name: upload-test-results
ignorePreviousStepErrors: true
image: upload-test-results
command: ['gsutil']
args: ['cp', '/workspace/test-results.xml', 'gs://mybucket/test-results.xml']
- name: deploy-to-prod
image: deploy-image
command: deployHow would this example execute?
- First the
node-run-testsstep would execute. - Let's say the unit tests fail.
- The next step,
publish-npm-packagewould be skipped. This is the behaviour we currently enforce with Tekton. - The next step,
upload-test-resultsincludes theignorePreviousStepErrorsfield and has it set to true. Therefore this step is executed regardless of the failure in the first step. - The final step,
deploy-to-proddoes not run because a prior step has failed. - Any subsequent steps (in the same Task) that also include
ignorePreviousStepErrors: truewould be allowed to run.
The TaskRun would end with a Failed status, since one of its steps ended with an error, but the step to upload test results would be allowed to run regardless.