How to exit the workflow if conditions met

Hello,

Is there any way to specify to exit the workflow if specific conditions are met by skipping the following steps?

I could not find any command that will do the abovementioned task in the documentation. I am looking for something similar to exit() in python.

Hello @HrishiDhondge ; can you take a look at Conditional workflows – Common Workflow Language User Guide and see if that helps you?

This would be very tedious to apply in my case. Can we somehow use this conditional to specify run only if a certain input file exists?

You could have an optional input and test for it’s existence in the when expression.

Something like when: $(inputs.my_opt_file === null) but I haven’t tested that.

1 Like

Hello,
I’m reopening this thread again because I would like to know if there is a conditional available to check the condition and if the condition met directly exit.

This conditional is best when I want to execute a step based on a condition but what if I want to skip all the next steps based on a condition?
Is there any conditional available for this purpose?

Thank you in advance!

The short answer is no, there is no shortcut to quit a CWL workflow early without failing the entire workflow.

Unlike make-like workflow systems, CWL and most DAG oriented workflow languages can’t arbitrary stop successfully in the middle.

You can throw a JavaScript exception inside any CWL expression, but beyond failing the workflow, the result is not predictable between engines. Some might give you partial outputs, some won’t.

It is possible to emulate the desired behavior, but not with a single construct. You would have to add a conditional to every step past a certain point, to see if the workflow should be short circuited. And then you would have to modify the outputs section to cope with the possibly skipped steps, by making those “later” outputs optional.

Thank you for the clarification.

1 Like