-
Is it possible to add a condition to a task in a DAG that is based on whether or not an artifact from the previous step was produced? The situation I'm running into is our main task finds no output and thus writes no output files. I do not want the follow on tasks to execute if no file was produced. Any thoughts or pointers would be appreciated. A contrived example that loosely resembles what we are trying to do is: apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: dag-conditional-artifacts-
spec:
entrypoint: main
templates:
- name: main
dag:
tasks:
- name: flip-coin
template: flip-coin
- name: heads
depends: flip-coin
template: heads
# We only want this task to execute if the output artifact exist
when: "{{tasks.flip-coin.outputs.artifacts.output}} == exists"
- name: flip-coin
script:
image: python:alpine3.6
command: [ python ]
source: |
import os
import random
val = random.randint(0, 1)
if val == 0:
fd = open("output.txt", "w")
fd.write("heads")
fd.close()
# We are not writing anything out if val is not 0
outputs:
artifacts:
- name: output
path: /output.txt
optional: true
- name: heads
script:
image: python:alpine3.6
command: [ python ]
inputs:
artifacts:
- name: output
path: /output.txt
optional: true
source: |
with open("/output.txt", "r") as f:
print(r.read()) |
Beta Was this translation helpful? Give feedback.
Answered by
agilgur5
Sep 4, 2023
Replies: 1 comment 1 reply
-
I believe this exact syntax should be possible, based on the Conditionals example. Did it not work? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
agilgur5
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe this exact syntax should be possible, based on the Conditionals example. Did it not work?