reg and deReg

reg and deReg cmd is used to register a variable or remove a variable

reg cmd spec

reg will automatically register it to global runtime vars map

 -  name: reg
    desc: description
    cmd:
      name: this is varname it will register to
      value: this is the value, or dvar to be assigned to the varname
    flags:
      - localOnly

deReg cmd spec

reg will automatically register it to global runtime vars map

  -
    name: deReg
    desc: demo of deReg command
    cmd: this_will_be_the_var_name_to_be_removed

localOnly flag

Indicating if this var only availbe in the local scope within one func call by default, it register the var to global scope

note

Compare to the template pipeline reg/deReg command, the difference of these two command here reg and deReg the vars immediately in the current func step, rather than the next func step. Check it out the demo step

Demo

source

Main task yaml file
    vars:
      student:
        name: Tom
        gender: Male
        school: Sydney Grammar
    tasks:
    - name: task
      task:
      - func: shell
        do:
        - echo "hello 1"
      - func: cmd
        dvars:
        - name: school
          value: "{{.student.school}}"
        do:
        - name: print
          desc: demo of print command
          cmd: "hello, {{.student.school}}"
        - name: reg
          desc: demo of reg command
          cmd:
            name: greet
            value: "from local dvars, {{.school}}. registered to global runtime"
        - name: print
          desc: |
            show above reg var greet and it is available immediately in current func
            unlike the reg in template, it is available in the next step func execution
          cmd: "hello, {{.greet}}"
        - name: reg
          desc: |
            demo greetlocal is registered to local var only
            it is accessible in current func, but not next one
          cmd:
            name: greetlocal
            value: "hello, {{.student.school}}. registered to local func only"
          flags:
          - localOnly
        - name: print
          desc: |
            this show display a correct rendered value
          cmd: "hello, {{.greetlocal}}"
      - func: cmd
        desc: the greetlocal will not be availe in this func call
        do:
        - name: print
          desc: |
            this will show the registered global runtime var
          cmd: "hello, {{.greetlocal}}"
        - name: print
          desc: |
            this will show <no value> for greetlocal, as it is not registered to global
          cmd: "hello, {{.greet}}"
      - func: cmd
        do:
        - name: deReg
          desc: demo of deReg command
          cmd: greet
      - func: shell
        desc: |
          you will see that greet var is removed from global var map
          you will see <no value> here
        do:
        - echo "hello {{.greet}}"
    
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 -> c0066
                 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/c0066
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "gender": "Male",
        "school": "Sydney Grammar",
        "name": "Tom"
      },
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "hello 1"
    
    -
    hello 1
    
    -
     .. ok
    . ok
    -Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "school": "Sydney Grammar",
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"hello 1\"",
        Code: 0,
        Output: "hello 1",
        ErrMsg: ""
      }),
      "student": {
        "name": "Tom",
        "gender": "Male",
        "school": "Sydney Grammar"
      }
    })
    
    ~SubStep1: [print: demo of print command ]
    hello, Sydney Grammar
    ~SubStep2: [reg: demo of reg command ]
    ~SubStep3: [print: show above reg var greet and it is available immediately in current func
    unlike the reg in template, it is available in the next step func execution
     ]
    hello, from local dvars, Sydney Grammar. registered to global runtime
    ~SubStep4: [reg: demo greetlocal is registered to local var only
    it is accessible in current func, but not next one
     ]
    ~SubStep5: [print: this show display a correct rendered value
     ]
    hello, hello, Sydney Grammar. registered to local func only
    -Step3: [: the greetlocal will not be availe in this func call ]
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "school": "Sydney Grammar",
        "name": "Tom",
        "gender": "Male"
      },
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"hello 1\"",
        Code: 0,
        Output: "hello 1",
        ErrMsg: ""
      }),
      "greet": "from local dvars, Sydney Grammar. registered to global runtime",
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [print: this will show the registered global runtime var
     ]
    hello, <no value>
    ~SubStep2: [print: this will show <no value> for greetlocal, as it is not registered to global
     ]
    hello, from local dvars, Sydney Grammar. registered to global runtime
    -Step4:
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "school": "Sydney Grammar",
        "name": "Tom",
        "gender": "Male"
      },
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"hello 1\"",
        Code: 0,
        Output: "hello 1",
        ErrMsg: ""
      }),
      "greet": "from local dvars, Sydney Grammar. registered to global runtime",
      "up_runtime_task_layer_number": 0
    })
    
    ~SubStep1: [deReg: demo of deReg command ]
    deRegister var: greet
    -Step5: [
    you will see that greet var is removed from global var map
    you will see <no value> here
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "student": {
        "name": "Tom",
        "gender": "Male",
        "school": "Sydney Grammar"
      },
      "last_result": (*utils.ExecResult)({
        Cmd: "echo \"hello 1\"",
        Code: 0,
        Output: "hello 1",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    echo "hello {{.greet}}"
    
    -
    hello <no value>
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level