You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously the docs for using when expressions to guard steps was under
the StepActions docs. It was moved to the Tasks docs under
"Tasks > Configuring a Task > Defining Steps > Guarding Step execution
using when expressions".
Issue #8623
Signed-off-by: Stanislav Jakuschevskij <[email protected]>
-[Controlling Step Execution with when Expressions](#controlling-step-execution-with-when-expressions)
22
21
23
22
## Overview
24
23
> :seedling:**`StepActions` is an [beta](additional-configs.md#beta-features) feature.**
@@ -536,104 +535,3 @@ spec:
536
535
```
537
536
538
537
The default resolver type can be configured by the `default-resolver-type` field in the `config-defaults` ConfigMap (`alpha` feature). See [additional-configs.md](./additional-configs.md) for details.
539
-
540
-
### Controlling Step Execution with when Expressions
541
-
542
-
You can define `when` in a `step` to control its execution.
543
-
544
-
The components of `when` expressions are `input`, `operator`, `values`, `cel`:
| `input` | Input for the `when` expression, defaults to an empty string if not provided. | * Static values e.g. `"ubuntu"`<br/> * Variables (parameters or results) e.g. `"$(params.image)"` or `"$(tasks.task1.results.image)"` or `"$(tasks.task1.results.array-results[1])"` |
549
-
| `operator` | `operator` represents an `input`'s relationship to a set of `values`, a valid `operator` must be provided. | `in` or `notin` |
550
-
| `values` | An array of string values, the `values` array must be provided and has to be non-empty. | * An array param e.g. `["$(params.images[*])"]`<br/> * An array result of a task `["$(tasks.task1.results.array-results[*])"]`<br/> * An array result of a step`["(steps.step1.results.array-results[*])"]`<br/>* `values` can contain static values e.g. `"ubuntu"`<br/> * `values` can contain variables (parameters or results) or a Workspaces's `bound` state e.g. `["$(params.image)"]` or `["$(steps.step1.results.image)"]` or `["$(tasks.task1.results.array-results[1])"]` or `["$(steps.step1.results.array-results[1])"]` |
551
-
| `cel` | The Common Expression Language (CEL) implements common semantics for expression evaluation, enabling different applications to more easily interoperate. This is an `alpha` feature, `enable-cel-in-whenexpression` needs to be set to true to use this feature. | [cel-syntax](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax)
552
-
553
-
The below example shows how to use when expressions to control step executions:
554
-
555
-
```yaml
556
-
apiVersion: v1
557
-
kind: PersistentVolumeClaim
558
-
metadata:
559
-
name: my-pvc-2
560
-
spec:
561
-
resources:
562
-
requests:
563
-
storage: 5Gi
564
-
volumeMode: Filesystem
565
-
accessModes:
566
-
- ReadWriteOnce
567
-
---
568
-
apiVersion: tekton.dev/v1
569
-
kind: TaskRun
570
-
metadata:
571
-
generateName: step-when-example
572
-
spec:
573
-
workspaces:
574
-
- name: custom
575
-
persistentVolumeClaim:
576
-
claimName: my-pvc-2
577
-
taskSpec:
578
-
description: |
579
-
A simple task that shows how to use when determine if a step should be executed
580
-
steps:
581
-
- name: should-execute
582
-
image: bash:latest
583
-
script: |
584
-
#!/usr/bin/env bash
585
-
echo "executed..."
586
-
when:
587
-
- input: "$(workspaces.custom.bound)"
588
-
operator: in
589
-
values: [ "true" ]
590
-
- name: should-skip
591
-
image: bash:latest
592
-
script: |
593
-
#!/usr/bin/env bash
594
-
echo skipskipskip
595
-
when:
596
-
- input: "$(workspaces.custom2.bound)"
597
-
operator: in
598
-
values: [ "true" ]
599
-
- name: should-continue
600
-
image: bash:latest
601
-
script: |
602
-
#!/usr/bin/env bash
603
-
echo blabalbaba
604
-
- name: produce-step
605
-
image: alpine
606
-
results:
607
-
- name: result2
608
-
type: string
609
-
script: |
610
-
echo -n "foo" | tee $(step.results.result2.path)
611
-
- name: run-based-on-step-results
612
-
image: alpine
613
-
script: |
614
-
echo "wooooooo"
615
-
when:
616
-
- input: "$(steps.produce-step.results.result2)"
617
-
operator: in
618
-
values: [ "bar" ]
619
-
workspaces:
620
-
- name: custom
621
-
```
622
-
623
-
The StepState for a skipped step looks like something similar to the below:
> - There is currently a limit on the overall size of the `Task` results. If the stdout/stderr of a step is set to the path of a `Task` result and the step prints too many data, the result manifest would become too large. Currently the entrypoint binary will fail if that happens.
554
555
> - If the stdout/stderr of a `Step` is set to the path of a `Task` result, e.g. `$(results.empty.path)`, but that result is not defined for the `Task`, the `Step` will run but the output will be captured in a file named `$(results.empty.path)` in the current working directory. Similarly, any stubstition that is not valid, e.g. `$(some.invalid.path)/out.txt`, will be left as-is and will result in a file path `$(some.invalid.path)/out.txt` relative to the current working directory.
555
556
557
+
#### Guarding `Step` execution using `when` expressions
558
+
559
+
You can define `when` in a `step` to control its execution.
560
+
561
+
The components of `when` expressions are `input`, `operator`, `values`, `cel`:
| `input` | Input for the `when` expression, defaults to an empty string if not provided. | * Static values e.g. `"ubuntu"`<br/> * Variables (parameters or results) e.g. `"$(params.image)"` or `"$(tasks.task1.results.image)"` or `"$(tasks.task1.results.array-results[1])"` |
566
+
| `operator` | `operator` represents an `input`'s relationship to a set of `values`, a valid `operator` must be provided. | `in` or `notin` |
567
+
| `values` | An array of string values, the `values` array must be provided and has to be non-empty. | * An array param e.g. `["$(params.images[*])"]`<br/> * An array result of a task `["$(tasks.task1.results.array-results[*])"]`<br/> * An array result of a step`["(steps.step1.results.array-results[*])"]`<br/>* `values` can contain static values e.g. `"ubuntu"`<br/> * `values` can contain variables (parameters or results) or a Workspaces's `bound` state e.g. `["$(params.image)"]` or `["$(steps.step1.results.image)"]` or `["$(tasks.task1.results.array-results[1])"]` or `["$(steps.step1.results.array-results[1])"]` |
568
+
| `cel` | The Common Expression Language (CEL) implements common semantics for expression evaluation, enabling different applications to more easily interoperate. This is an `alpha` feature, `enable-cel-in-whenexpression` needs to be set to true to use this feature. | [cel-syntax](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax)
569
+
570
+
The below example shows how to use when expressions to control step executions:
571
+
572
+
```yaml
573
+
apiVersion: v1
574
+
kind: PersistentVolumeClaim
575
+
metadata:
576
+
name: my-pvc-2
577
+
spec:
578
+
resources:
579
+
requests:
580
+
storage: 5Gi
581
+
volumeMode: Filesystem
582
+
accessModes:
583
+
- ReadWriteOnce
584
+
---
585
+
apiVersion: tekton.dev/v1
586
+
kind: TaskRun
587
+
metadata:
588
+
generateName: step-when-example
589
+
spec:
590
+
workspaces:
591
+
- name: custom
592
+
persistentVolumeClaim:
593
+
claimName: my-pvc-2
594
+
taskSpec:
595
+
description: |
596
+
A simple task that shows how to use when determine if a step should be executed
597
+
steps:
598
+
- name: should-execute
599
+
image: bash:latest
600
+
script: |
601
+
#!/usr/bin/env bash
602
+
echo "executed..."
603
+
when:
604
+
- input: "$(workspaces.custom.bound)"
605
+
operator: in
606
+
values: [ "true" ]
607
+
- name: should-skip
608
+
image: bash:latest
609
+
script: |
610
+
#!/usr/bin/env bash
611
+
echo skipskipskip
612
+
when:
613
+
- input: "$(workspaces.custom2.bound)"
614
+
operator: in
615
+
values: [ "true" ]
616
+
- name: should-continue
617
+
image: bash:latest
618
+
script: |
619
+
#!/usr/bin/env bash
620
+
echo blabalbaba
621
+
- name: produce-step
622
+
image: alpine
623
+
results:
624
+
- name: result2
625
+
type: string
626
+
script: |
627
+
echo -n "foo" | tee $(step.results.result2.path)
628
+
- name: run-based-on-step-results
629
+
image: alpine
630
+
script: |
631
+
echo "wooooooo"
632
+
when:
633
+
- input: "$(steps.produce-step.results.result2)"
634
+
operator: in
635
+
values: [ "bar" ]
636
+
workspaces:
637
+
- name: custom
638
+
```
639
+
640
+
The StepState for a skipped step looks like something similar to the below:
0 commit comments