github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/f0186.yml (about) 1 doc_meta: | 2 folder: flow-controll 3 title: finally/resuce support in subtask level 4 head: | 5 Showcases the compex sub task with finally block without ignoreError flag 6 7 sections: 8 - title: Demo 9 log: yes 10 11 - title: What's the difference betwee the step level and task level finally cleanup and rescue? 12 content: | 13 The only difference would be that in the step level, you would be able to obtain the exec result and then conditionally do something about it 14 15 related: 16 refs: 17 - title: shell func 18 link: ../../quick-start/c0002/ 19 - title: error handling 20 link: ../../test-debug/error_handling/ 21 - title: finally and rescue 22 link: ../../flow-controll/c0174/ 23 24 notes: 25 - add finally support to tasks level 26 27 tasks: 28 29 - 30 name: task 31 task: 32 33 - 34 func: block 35 loop: 36 - item1 37 - item2 38 desc: task 39 do: 40 - func: call 41 do: sub_task_layer1 42 43 - 44 name: sub_task_layer1 45 desc: sub_task_layer1 46 task: 47 48 - 49 func: cmd 50 do: 51 - name: print 52 cmd: "in sub_task_layer1" 53 54 - 55 func: call 56 loop: 57 - aaa 58 - bbb 59 do: 60 - sub_task_layer2 61 62 - 63 name: sub_task_layer2 64 task: 65 66 - 67 func: shell 68 name: step1 69 desc: step 1 70 do: 71 - 'echo """opening file: {{.loopitem}}"""' 72 - echo "hello"|grep "world" 73 74 - 75 func: cmd 76 name: step2 77 desc: | 78 in this case, since there is no ignoreError, the exception was captured by task level finaly code block 79 opened file is safely closed 80 to make the flow to continue to reach step2, use ignoreError 81 do: 82 - name: print 83 cmd: step 2 84 85 desc: | 86 without rescue, the execution will return a non-zero return code in shell and also report the error 87 with rescue, the program will return 0 88 rescue: true 89 finally: 90 - 91 func: shell 92 name: close_file 93 desc: | 94 ensure the opened file is closed 95 do: 96 - echo "close the file ....."