finally steps block

Introduce to use the func block instead of routing it to a task

Demo

source

Main task yaml file
    vars:
      global_aaa: aaa
    tasks:
    - name: task
      task:
      - func: cmd
        desc: step 1
        vars:
          local_aaa: local_aaa
        do:
        - name: print
          cmd: step 1
        - name: panic
        - name: print
          cmd: extra step ......... it will never reach here
        rescue: true
        finally:
        - func: cmd
          do:
          - name: print
            cmd: 'global aaa: {{.global_aaa}}'
          - name: print
            cmd: 'local aaa: {{.local_aaa}}'
        - func: shell
          name: close_file
          desc: |
            ensure the opened file is closed
          do:
          - echo "close the file ....."
        - func: cmd
          desc: extra steps
          do:
          - name: print
            cmd: extra step
      - func: cmd
        desc: step 2
        do:
        - name: print
          cmd: step 2
    
Main log file
    loading [Config]:  ./tests/functests/upconfig.yml
    Main config:
                 Version -> 1.0.0
                  RefDir -> ./tests/functests
                 WorkDir -> cwd
              AbsWorkDir -> /up_project/up
                TaskFile -> c0173
                 Verbose -> vvv
              ModuleName -> self
               ShellType -> /bin/sh
           MaxCallLayers -> 8
                 Timeout -> 3600000
     MaxModuelCallLayers -> 256
               EntryTask -> task
      ModRepoUsernameRef -> 
      ModRepoPasswordRef -> 
    work dir: /up_project/up
    -exec task: task
    loading [Task]:  ./tests/functests/c0173
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [: step 1 ]
    self: final context exec vars:
    
    (*core.Cache)({
      "global_aaa": "aaa",
      "up_runtime_task_layer_number": 0,
      "local_aaa": "local_aaa"
    })
    
    ~SubStep1: [print:  ]
    step 1
    ~SubStep2: [panic:  ]
     WARN: [manual panic] - [manual trigger a panic cmd]
    Step Finally:
    Recovered from: manual trigger a panic cmd
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "global_aaa": "aaa",
      "up_runtime_task_layer_number": 0,
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>),
      "local_aaa": "local_aaa"
    })
    
    ~SubStep1: [print:  ]
    global aaa: aaa
    ~SubStep2: [print:  ]
    local aaa: local_aaa
    -Step2: [
    close_fileensure the opened file is closed
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "local_aaa": "local_aaa",
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>),
      "global_aaa": "aaa"
    })
    
    cmd( 1):
    echo "close the file ....."
    
    -
    close the file .....
    
    -
     .. ok
    . ok
    -Step3: [: extra steps ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "local_aaa": "local_aaa",
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>),
      "global_aaa": "aaa",
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"close the file .....\"",
        Code: 0,
        Output: "close the file .....",
        ErrMsg: ""
      })
    })
    
    ~SubStep1: [print:  ]
    extra step
     WARN: [Rescued in step level, but not advised!] - [setting rescue to yes/true to continue is not recommended
    it is advised to locate root cause of the problem, fix it and re-run the task again
    it is the best practice to test the execution in your ci pipeline to eliminate problems rather than dynamically fix using rescue]
    -Step2: [: step 2 ]
    self: final context exec vars:
    
    (*core.Cache)({
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"close the file .....\"",
        Code: 0,
        Output: "close the file .....",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0,
      "global_aaa": "aaa"
    })
    
    ~SubStep1: [print:  ]
    step 2
    
Logs with different verbose level
Raw logs with different verbose level

use the anonymouse func block

Compare to the example of c0172, this shows that you can simply use a steps block for the cleanup steps

Other references: