-
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.
Adding `WhenExpressions` used to efficiently specify guarded execution of `Tasks`, without spinning up new pods. We use `WhenExpressions` to avoid adding an opinionated andcomplex expression language to the Tekton API to ensure Tekton can be supported by as many systems as possible. The components of `WhenExpressions` are `Input`, `Operator` and `Values`: - `Input` is the input for the `Guard` checking which can be static inputs or variables, such as `Parameters` or `Results`. - `Values` is an array of string values. The `Values` array must be non-empty. It can contain static values or variables (`Parameters` or `Results`). - `Operator` represents an `Input`'s relationship to a set of `Values`. `Operators` we will use in `WhenExpressions` are `In` and `NotIn`. The declared `WhenExpressions` are evaluated before the `Task` is run. If all the `WhenExpressions` evaluate to `True`, the `Task` is run. If any of the `WhenExpressions` evaluate to `False`, the `Task` is skipped. Further details in [Conditions Beta TEP](https://github.com/tektoncd/community/blob/master/teps/0007-conditions-beta.md).
- Loading branch information
Showing
21 changed files
with
1,988 additions
and
25 deletions.
There are no files selected for viewing
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
123 changes: 123 additions & 0 deletions
123
examples/v1beta1/pipelineruns/pipelinerun-with-when-expressions.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,123 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: create-readme-file | ||
spec: | ||
resources: | ||
outputs: | ||
- name: workspace | ||
type: git | ||
steps: | ||
- name: write-new-stuff | ||
image: ubuntu | ||
script: 'touch $(resources.outputs.workspace.path)/README.md' | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: check-file | ||
spec: | ||
params: | ||
- name: path | ||
resources: | ||
inputs: | ||
- name: workspace | ||
type: git | ||
results: | ||
- name: status | ||
description: indicating whether the file exists | ||
steps: | ||
- name: check-file | ||
image: alpine | ||
script: | | ||
if test -f $(resources.inputs.workspace.path)/$(params.path); then | ||
printf exists | tee /tekton/results/status | ||
else | ||
printf missing | tee /tekton/results/status | ||
fi | ||
--- | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: PipelineResource | ||
metadata: | ||
name: pipeline-git | ||
spec: | ||
type: git | ||
params: | ||
- name: revision | ||
value: master | ||
- name: url | ||
value: https://github.com/tektoncd/pipeline | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
name: echo-file-status | ||
spec: | ||
params: | ||
- name: status | ||
steps: | ||
- name: echo | ||
image: ubuntu | ||
script: 'echo file $(params.status)' | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Pipeline | ||
metadata: | ||
name: guarded-pipeline | ||
spec: | ||
resources: | ||
- name: source-repo | ||
type: git | ||
params: | ||
- name: path | ||
default: "README.md" | ||
tasks: | ||
- name: first-create-file | ||
when: | ||
- input: "$(params.path)" | ||
operator: in | ||
values: ["README.md"] | ||
taskRef: | ||
name: create-readme-file | ||
resources: | ||
outputs: | ||
- name: workspace | ||
resource: source-repo | ||
- name: check-file | ||
when: | ||
- input: "foo" | ||
operator: in | ||
values: ["foo", "bar"] | ||
taskRef: | ||
name: check-file | ||
params: | ||
- name: path | ||
value: "$(params.path)" | ||
resources: | ||
inputs: | ||
- name: workspace | ||
resource: source-repo | ||
from: [first-create-file] | ||
- name: echo-file-exists | ||
params: | ||
- name: status | ||
value: "$(tasks.check-file.results.status)" | ||
when: | ||
- input: "$(tasks.check-file.results.status)" | ||
operator: in | ||
values: ["exists"] | ||
taskRef: | ||
name: echo-file-status | ||
--- | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: PipelineRun | ||
metadata: | ||
name: guarded-pr | ||
spec: | ||
pipelineRef: | ||
name: guarded-pipeline | ||
serviceAccountName: 'default' | ||
resources: | ||
- name: source-repo | ||
resourceRef: | ||
name: 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.