use dynamic variable in until

This shows how to use a dynamic variable to end the loop, which uses a changing variable in block func, callee task

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: block
        desc: |
          break loop using until condition
        do:
        - func: cmd
          do:
          - name: print
            cmd: '{{.loopitem}}'
        loop:
        - item1
        - item2
        - item3
        - item4
        - item5
        - item6
        until: '{{eq .loopitem "item4"}}'
      - func: cmd
        do:
        - name: print
          cmd: '----------------------------------------------------'
      - func: block
        desc: |
          in this case the until condition will use a var which is chaning in block func
          in order to make the interal var accessible by parent block func, you will have to use return cmd to return the value, otherwise the block func can not use right changing value in the condition
          also the_internal_var has be be defined somewhere: scope/global/local, otherwise it will result in a golang templating error
        dvars:
        - name: the_internal_var
          value: 'None'
        do:
        - func: cmd
          dvars:
          - name: the_internal_var
            value: '{{.loopitem}}'
            flags:
            - taskScope
          do:
          - name: print
            cmd: '{{.loopitem}}'
          - name: return
            cmd:
            - the_internal_var
        - func: cmd
          do:
          - name: print
            cmd: 'post process {{.the_internal_var}} to see if this is executed'
        loop:
        - item1
        - item2
        - item3
        - item4
        - item5
        - item6
        until: '{{eq .the_internal_var "item4"}}'
      - func: cmd
        do:
        - name: print
          cmd: '----------------------------------------------------'
      - func: call
        vars:
          the_internal_var2: 'None'
        do: sub_task
        loop:
        - item1
        - item2
        - item3
        - item4
        - item5
        - item6
        until: '{{eq .the_internal_var2 "item4"}}'
      - func: cmd
        do:
        - name: inspect
          cmd:
          - exec_vars
    - name: sub_task
      task:
      - func: cmd
        dvars:
        - name: the_internal_var2
          value: '{{.loopitem}}'
        do:
        - name: print
          cmd: '{{.loopitem}}'
        - name: return
          cmd:
          - the_internal_var2
    
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 -> c0181
                 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/c0181
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [
    break loop using until condition
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex": 0,
      "loopindex1": 1,
      "up_runtime_task_layer_number": 0,
      "loopitem": "item1"
    })
    
    ~SubStep1: [print:  ]
    item1
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopitem": "item2",
      "loopindex": 1,
      "loopindex1": 2,
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    item2
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopitem": "item3",
      "loopindex": 2,
      "loopindex1": 3,
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    item3
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    ----------------------------------------------------
    -Step3: [
    in this case the until condition will use a var which is chaning in block func
    in order to make the interal var accessible by parent block func, you will have to use return cmd to return the value, otherwise the block func can not use right changing value in the condition
    also the_internal_var has be be defined somewhere: scope/global/local, otherwise it will result in a golang templating error
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "None"
    })
    
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex1": 1,
      "the_internal_var": "item1",
      "loopitem": "item1",
      "up_runtime_task_layer_number": 0,
      "loopindex": 0
    })
    
    ~SubStep1: [print:  ]
    item1
    ~SubStep2: [return:  ]
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex1": 1,
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "None",
      "loopitem": "item1",
      "loopindex": 0
    })
    
    ~SubStep1: [print:  ]
    post process None to see if this is executed
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex1": 2,
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "item2",
      "loopitem": "item2",
      "loopindex": 1
    })
    
    ~SubStep1: [print:  ]
    item2
    ~SubStep2: [return:  ]
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "the_internal_var": "item1",
      "loopitem": "item2",
      "loopindex": 1,
      "loopindex1": 2,
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    post process item1 to see if this is executed
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "the_internal_var": "item3",
      "loopindex": 2,
      "loopindex1": 3,
      "loopitem": "item3",
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    item3
    ~SubStep2: [return:  ]
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "the_internal_var": "item2",
      "loopitem": "item3",
      "loopindex": 2,
      "loopindex1": 3,
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print:  ]
    post process item2 to see if this is executed
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopitem": "item4",
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "item4",
      "loopindex": 3,
      "loopindex1": 4
    })
    
    ~SubStep1: [print:  ]
    item4
    ~SubStep2: [return:  ]
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopitem": "item4",
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "item3",
      "loopindex": 3,
      "loopindex1": 4
    })
    
    ~SubStep1: [print:  ]
    post process item3 to see if this is executed
    -Step4:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "item4"
    })
    
    ~SubStep1: [print:  ]
    ----------------------------------------------------
    -Step5:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "the_internal_var": "item4",
      "the_internal_var2": "None"
    })
    
    =Task2: [task ==> sub_task:  ]
    --Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopitem": "item1",
      "loopindex": 0,
      "loopindex1": 1,
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4",
      "the_internal_var2": "item1"
    })
    
    ~~SubStep1: [print:  ]
    item1
    ~~SubStep2: [return:  ]
    =Task2: [task ==> sub_task:  ]
    --Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex": 1,
      "loopindex1": 2,
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4",
      "the_internal_var2": "item2",
      "loopitem": "item2"
    })
    
    ~~SubStep1: [print:  ]
    item2
    ~~SubStep2: [return:  ]
    =Task2: [task ==> sub_task:  ]
    --Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "loopindex": 2,
      "loopindex1": 3,
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4",
      "the_internal_var2": "item3",
      "loopitem": "item3"
    })
    
    ~~SubStep1: [print:  ]
    item3
    ~~SubStep2: [return:  ]
    =Task2: [task ==> sub_task:  ]
    --Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "the_internal_var2": "item4",
      "loopitem": "item4",
      "loopindex": 3,
      "loopindex1": 4,
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4"
    })
    
    ~~SubStep1: [print:  ]
    item4
    ~~SubStep2: [return:  ]
    -Step6:
    self: final context exec vars:
    
    (*core.Cache)({
      "the_internal_var2": "item4",
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4"
    })
    
    ~SubStep1: [inspect:  ]
     1: inspect[exec_vars]
    (*core.Cache)({
      "up_runtime_task_layer_number": 1,
      "the_internal_var": "item4",
      "the_internal_var2": "item4"
    })
    
    
Logs with different verbose level
Raw logs with different verbose level