forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression-reusing-verbose-snippets.yaml
44 lines (44 loc) · 1.76 KB
/
expression-reusing-verbose-snippets.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Expressions do not support variables. Rather than repeating verbose expressions to reuse output, you can map over the
# expression output and use its value which is aliased as `#`. Then you can place your "variables" in a JSON object to
# be used elsewhere.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: expression-reusing-verbose-snippets-
spec:
arguments:
parameters:
- name: weather
# The base64 string is this JSON: {"temps": [34, 27, 15, 57, 46]}
value: '{"weekWeather": "eyJ0ZW1wcyI6IFszNCwgMjcsIDE1LCA1NywgNDZdfQo="}'
entrypoint: main
templates:
- name: main
inputs:
parameters:
- name: week-temps
# The line being mapped over is verbose. Rather than repeat it, we use `map` to alias its output as #.
value: >-
{{=
map([
jsonpath(sprig.b64dec(jsonpath(workflow.parameters.weather, '$.weekWeather')), '$.temps')
], {
toJson({
avg: sprig.add(#[0], #[1], #[2], #[3], #[4]) / 5,
min: sprig.min(#[0], #[1], #[2], #[3], #[4]),
max: sprig.max(#[0], #[1], #[2], #[3], #[4])
})
})[0]
}}
script:
env:
- name: AVG
value: "{{=jsonpath(inputs.parameters['week-temps'], '$.avg')}}"
- name: MIN
value: "{{=jsonpath(inputs.parameters['week-temps'], '$.min')}}"
- name: MAX
value: "{{=jsonpath(inputs.parameters['week-temps'], '$.max')}}"
image: debian:9.4
command: [bash]
source: |
echo "The week's average temperature was $AVG with a minimum of $MIN and a maximum of $MAX."