last_result pass through block func

Even though calling a block func is same as calling an internal or external call func, the regular vars override from current task to the block, it means this will apply to last_result, so that the the last_result will be the value from parent called

This is to demo that the correct behavior should be that last_result will be an exception of the rule so that called func could get correct shell execution result

Be cautious that when you register a name the shell execution result, do not use the duplicated name in the block func, as the rule will make the caller’s var available in the funcs of the block, this will confuse you but it is correct.

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: shell
        do: echo hello
      - func: cmd
        do:
        - name: print
          cmd: '{{.last_result.Output}}'
      - func: block
        do:
        - func: shell
          do: echo world
        - func: cmd
          do:
          - name: print
            cmd: '{{.last_result.Output}}'
          - name: assert
            cmd:
            - '{{eq .last_result.Output "world" }}'
      - func: cmd
        desc: after the block func call
        do:
        - name: print
          cmd: '{{.last_result.Output}}'
        - name: assert
          cmd:
          - '{{eq .last_result.Output "world" }}'
    
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 -> c0179
                 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/c0179
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo hello
    
    -
    hello
    
    -
     .. ok
    . ok
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "last_result": (*utils.ExecResult)({
        Cmd: "echo hello",
        Code: 0,
        Output: "hello",
        ErrMsg: ""
      })
    })
    
    ~SubStep1: [print:  ]
    hello
    -Step3:
    self: final context exec vars:
    
    (*core.Cache)({
      "last_result": (*utils.ExecResult)({
        Cmd: "echo hello",
        Code: 0,
        Output: "hello",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0
    })
    
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo world
    
    -
    world
    
    -
     .. ok
    . ok
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "last_result": (*utils.ExecResult)({
        Cmd: "echo world",
        Code: 0,
        Output: "world",
        ErrMsg: ""
      })
    })
    
    ~SubStep1: [print:  ]
    world
    ~SubStep2: [assert:  ]
     1 ASSERT OK:     [{{eq .last_result.Output "world" }}]
    -Step4: [: after the block func call ]
    self: final context exec vars:
    
    (*core.Cache)({
      "last_result": (*utils.ExecResult)({
        Cmd: "echo world",
        Code: 0,
        Output: "world",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    world
    ~SubStep2: [assert:  ]
     1 ASSERT OK:     [{{eq .last_result.Output "world" }}]
    
Logs with different verbose level
Raw logs with different verbose level