forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdag-conditional-artifacts.yaml
67 lines (62 loc) · 1.97 KB
/
dag-conditional-artifacts.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-conditional-artifacts-
labels:
workflows.argoproj.io/test: "true"
annotations:
workflows.argoproj.io/description: |
Conditional artifacts provides a way to choose the output artifacts based on an expression.
In this example the DAG template has two tasks which will run conditionall using `when`.
Based on the condition one of steps may not execute. The step template output's artifact will be set to the
executed step's output artifacts.
workflows.argoproj.io/version: '>= 3.1.0'
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: flip-coin
template: flip-coin
- name: heads
depends: flip-coin
template: heads
when: "{{tasks.flip-coin.outputs.result}} == heads"
- name: tails
depends: flip-coin
template: tails
when: "{{tasks.flip-coin.outputs.result}} == tails"
outputs:
artifacts:
- name: result
fromExpression: "tasks['flip-coin'].outputs.result == 'heads' ? tasks.heads.outputs.artifacts.result : tasks.tails.outputs.artifacts.result"
- name: flip-coin
script:
image: python:alpine3.6
command: [ python ]
source: |
import random
print("heads" if random.randint(0,1) == 0 else "tails")
- name: heads
script:
image: python:alpine3.6
command: [ python ]
source: |
with open("result.txt", "w") as f:
f.write("it was heads")
outputs:
artifacts:
- name: result
path: /result.txt
- name: tails
script:
image: python:alpine3.6
command: [ python ]
source: |
with open("result.txt", "w") as f:
f.write("it was tails")
outputs:
artifacts:
- name: result
path: /result.txt