github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/f0171.yml (about) 1 doc_meta: | 2 folder: flow-controll 3 title: final cleanup when shell exceution fails 4 head: | 5 demo the finally element will guarantee the resource cleanup when shell execution fails 6 7 sections: 8 - title: Demo 9 log: yes 10 11 - title: what will happen if there is no ignoreError for the task 12 content: | 13 The shell step failed, the finally step invokes the close_file task to ensure the opened file is closed 14 15 In this way, user has the control to gracefully cleanup all relevant resources used and terminate the process to continue further. The task fails, but it is intended. 16 17 In case user would like to continue, use can still choose to use ignoreError, then it will continue to execute the "step 2" 18 19 related: 20 refs: 21 - title: shell func 22 link: ../../quick-start/c0002/ 23 - title: error handling 24 link: ../../test-debug/error_handling/ 25 26 tasks: 27 28 - 29 name: task 30 task: 31 32 - 33 func: shell 34 desc: | 35 task fails 36 do: 37 - echo "open a file ....." 38 - echo "reading the file" |grep "cause an exception" 39 finally: close_file 40 41 - 42 func: cmd 43 desc: step 2 44 do: 45 - name: print 46 cmd: step 2 47 48 - 49 name: close_file 50 task: 51 - 52 func: shell 53 name: close_file 54 desc: | 55 ensure the opened file is closed 56 do: 57 - echo "close the file ....."