-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample_try_catch_finally_and_foreach.yaml
49 lines (46 loc) · 1.17 KB
/
example_try_catch_finally_and_foreach.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
name: foreach_and_trycatch_example
steps:
- !Command
name: set_items
command: echo "item1,item2,item3"
save_output: item_list
- !ForEach
name: process_items
items: "${item_list}"
steps:
- !ShellCommand
name: process_item
command: echo "Processing ${ITEM}"
save_output: item_result
- !TryCatch
name: risky_operation
try_steps:
- !ShellCommand
name: risky_command
command: |
if [ "$RANDOM" -gt 16384 ]; then
echo "Success"
else
exit 1
fi
save_output: risky_result
catch_steps:
- !ShellCommand
name: error_handling
command: |
echo "An error occurred: ${error}"
save_output: error_message
finally_steps:
- !ShellCommand
name: cleanup
command: echo "Cleanup operation"
save_output: cleanup_result
- !PrintOutput
name: final_output
value: |
ForEach Results: ${process_items}
TryCatch Results:
Try Result: ${try_result}
Risky Operation Output: ${risky_result}
Error (if any): ${error_message}
Cleanup: ${cleanup_result}