-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing finally at the pipeline level
We can now specify a list of tasks needs to be executed just before pipeline exits (either after finishing all non-final tasks successfully or after a single failure) Most useful for tasks such as report test results, cleanup cluster resources, etc ``` apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: name: pipeline-with-final-tasks spec: tasks: - name: pre-work taskRef: Name: some-pre-work - name: unit-test taskRef: Name: run-unit-test runAfter: - pre-work - name: integration-test taskRef: Name: run-integration-test runAfter: - unit-test finally: - name: cleanup-test taskRef: Name: cleanup-cluster - name: report-results taskRef: Name: report-test-results ```
- Loading branch information
1 parent
25b2446
commit 9279df2
Showing
17 changed files
with
1,120 additions
and
147 deletions.
There are no files selected for viewing
236 changes: 236 additions & 0 deletions
236
examples/v1beta1/pipelineruns/pipelinerun-with-final-tasks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
# Task producing success by exiting with 0 | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: successful-task | ||
spec: | ||
steps: | ||
- name: success | ||
image: ubuntu | ||
script: | | ||
exit 0 | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
name: pipeline-with-final-tasks | ||
spec: | ||
tasks: | ||
- name: pre-work | ||
taskRef: | ||
Name: successful-task | ||
- name: unit-test | ||
taskRef: | ||
Name: successful-task | ||
runAfter: | ||
- pre-work | ||
- name: integration-test | ||
taskRef: | ||
Name: successful-task | ||
runAfter: | ||
- unit-test | ||
finally: | ||
- name: cleanup-test | ||
taskRef: | ||
Name: successful-task | ||
- name: report-results | ||
taskRef: | ||
Name: successful-task | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: pipelinerun-with-final-tasks | ||
spec: | ||
pipelineRef: | ||
name: pipeline-with-final-tasks | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: sum | ||
annotations: | ||
description: | | ||
A simple task that sums the two provided integers | ||
spec: | ||
params: | ||
- name: a | ||
type: string | ||
default: "1" | ||
description: The first integer | ||
- name: b | ||
type: string | ||
default: "1" | ||
description: The second integer | ||
results: | ||
- name: sum | ||
description: The sum of the two provided integers | ||
steps: | ||
- name: sum | ||
image: bash:latest | ||
script: | | ||
#!/usr/bin/env bash | ||
echo -n $(( "$(params.a)" + "$(params.b)" )) | tee $(results.sum.path) | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: format-result | ||
spec: | ||
params: | ||
- name: result | ||
type: string | ||
default: "0" | ||
steps: | ||
- name: print-sum | ||
image: ubuntu | ||
script: echo "*** Result = $(params.result) ***" | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
name: sum-and-print-pipeline | ||
spec: | ||
params: | ||
- name: a | ||
type: string | ||
default: "1" | ||
- name: b | ||
type: string | ||
default: "1" | ||
tasks: | ||
- name: sum-inputs | ||
taskRef: | ||
name: sum | ||
params: | ||
- name: a | ||
value: "$(params.a)" | ||
- name: b | ||
value: "$(params.b)" | ||
finally: | ||
- name: print-sum | ||
taskRef: | ||
name: format-result | ||
params: | ||
- name: result | ||
value: "$(tasks.sum-inputs.results.sum)" | ||
--- | ||
|
||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: sum-and-print-pipeline-run | ||
spec: | ||
pipelineRef: | ||
name: sum-and-print-pipeline | ||
params: | ||
- name: a | ||
value: "100" | ||
- name: b | ||
value: "1000" | ||
--- | ||
|
||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
metadata: | ||
name: shared-workspace | ||
spec: | ||
resources: | ||
requests: | ||
storage: 16Mi | ||
volumeMode: Filesystem | ||
accessModes: | ||
- ReadWriteOnce | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: clone-app-repo-to-workspace | ||
spec: | ||
workspaces: | ||
- name: shared-workspace | ||
resources: | ||
inputs: | ||
- name: app-git | ||
type: git | ||
targetPath: application | ||
steps: | ||
- name: clone-app-repo-to-workspace | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
set -xe | ||
cp -avr $(resources.inputs.app-git.path)/ $(workspaces.shared-workspace.path)/ | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Task | ||
metadata: | ||
name: cleanup-workspace | ||
spec: | ||
workspaces: | ||
- name: shared-workspace | ||
steps: | ||
- name: cleanup-workspace | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
set -xe | ||
rm -rf $(workspaces.shared-workspace.path)/application/ | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: Pipeline | ||
metadata: | ||
name: clone-into-workspace-and-cleanup-workspace | ||
spec: | ||
resources: | ||
- name: app-git | ||
type: git | ||
workspaces: | ||
- name: shared-workspace | ||
tasks: | ||
- name: clone-app-source | ||
taskRef: | ||
name: clone-app-repo-to-workspace | ||
workspaces: | ||
- name: shared-workspace | ||
workspace: shared-workspace | ||
resources: | ||
inputs: | ||
- name: app-git | ||
resource: app-git | ||
finally: | ||
- name: cleanup-workspace | ||
taskRef: | ||
name: cleanup-workspace | ||
workspaces: | ||
- name: shared-workspace | ||
workspace: shared-workspace | ||
--- | ||
|
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineRun | ||
metadata: | ||
name: write-and-cleanup-workspace | ||
spec: | ||
pipelineRef: | ||
name: clone-into-workspace-and-cleanup-workspace | ||
workspaces: | ||
- name: shared-workspace | ||
persistentVolumeClaim: | ||
claimName: shared-workspace | ||
resources: | ||
- name: app-git | ||
resourceSpec: | ||
type: git | ||
params: | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline.git | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.