-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Conditional Artifacts and Parameters (#4987)
- Loading branch information
1 parent
1a8ce1f
commit 78ec644
Showing
28 changed files
with
1,571 additions
and
552 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Conditional Artifacts and Parameters | ||
|
||
> v3.1 and after | ||
The Conditional Artifacts and Parameters feature enables to assign the Step/DAG level artifacts or parameters based on | ||
expression. This introduces a new field `fromExpression: ...` under Step/DAG level output artifact and `expression: ...` | ||
under step/DAG level output parameter. Both use the | ||
[expr](https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md) syntax. | ||
|
||
## Conditional Artifacts | ||
|
||
```yaml | ||
|
||
- name: coinflip | ||
steps: | ||
- - name: flip-coin | ||
template: flip-coin | ||
- - name: heads | ||
template: heads | ||
when: "{{steps.flip-coin.outputs.result}} == heads" | ||
- name: tails | ||
template: tails | ||
when: "{{steps.flip-coin.outputs.result}} == tails" | ||
outputs: | ||
artifacts: | ||
- name: result | ||
fromExpression: "steps['flip-coin'].outputs.result == 'heads' ? steps.heads.outputs.artifacts.headsresult : steps.tails.outputs.artifacts.tailsresult" | ||
|
||
``` | ||
|
||
* [Steps artifacts example](examples/conditional-artifacts.yaml) | ||
* [DAG artifacts example](examples/dag-conditional-artifacts.yaml) | ||
|
||
## Conditional Parameters | ||
|
||
```yaml | ||
- name: coinflip | ||
steps: | ||
- - name: flip-coin | ||
template: flip-coin | ||
- - name: heads | ||
template: heads | ||
when: "{{steps.flipcoin.outputs.result}} == heads" | ||
- name: tails | ||
template: tails | ||
when: "{{steps.flipcoin.outputs.result}} == tails" | ||
outputs: | ||
parameters: | ||
- name: stepresult | ||
valueFrom: | ||
expression: "steps.flipcoin.outputs.result == 'heads' ? steps.heads.outputs.result : steps.tails.outputs.result" | ||
``` | ||
|
||
* [Steps parameter example](examples/conditional-parameters.yaml) | ||
* [DAG parameter example](examples/dag-conditional-parameters.yaml) | ||
|
||
## Build-In Functions | ||
|
||
Convenient functions added to support more use cases: | ||
|
||
1. `asInt` - convert the string to integer (e.g: `asInt('1')`) | ||
2. `asFloat` - convert the string to Float (e.g: `asFloat('1.23')`) | ||
3. `string` - convert the int/float to string (e.g: `string(1)`) | ||
4. `jsonpath` - Extract the element from Json using jsonpath ( | ||
e.g: `jsonpath('{"employee":{"name":"sonoo","salary":56000,"married":true}}", "$.employee.name" )` ) | ||
5. [Sprig](http:https://masterminds.github.io/sprig/) - Support all `sprig` functions | ||
|
||
* [Advanced example: fibonacci Sequence](examples/fibonacci-seq-conditional-param.yaml) | ||
|
||
!!! NOTE | ||
Expressions will decode the `-` as operator if template name has `-`, it will fail the expression. So here solution | ||
for template name which has `-` in its name. `step['one-two-three'].outputs.artifacts` |
Oops, something went wrong.