dvars intro

dvar stands for dynamic var. As suggested by the naming, dvar is like a calculated variable during runtime, we call this behavior as expansion. A dvar’s value is expressed using golang template, it could be the case that a expanded result contains another template variable, so that you will need to expand it again.

By default the expand level is 1, but you can custmise it to be multiple depending on your own needs

We use array to configure a entry of dvar item, the sequence matters as the value of dvar will be evaluated sequentially, the later one will need to reference to the evaluated value of another dvar

A validation rule is that the name of a dvar should should not contiain “-” as it will conflict with golang template var naming

Note

Please take note the demo cases that use multiple expansion, it is dynamic on dynamic and it is usful in certain cases. Please read the self explanation of the description in dvar config

Demo

source

Main task yaml file
    vars:
      student: Tom
      gender: Male
      school: Sydney Grammar
      a1: a1->{{.b2}}
      b2: b2->{{.c3}}
      c3: c3->{{.d4}}
      d4: d4->{{.student}}
    dvars:
    - name: from
      value: "{{.school}}"
      desc: |
        default expanding level is 1
        you will have to quote it if it starts the value of bracket since yaml uses it
    - name: sex
      value: "{{.gender}}"
      expand: 1
    - name: dependon_vars
      value: "{{.sex}}"
    - name: dependon_var_and_dvar
      value: "{{.student}}-{{.sex}}"
      desc: this is still 1 level expanding as .sex must be rendered and merged into runtimevars
    - name: multple_render_var_level3
      value: multple-render-var-> {{.b2}}
      desc: |
        you don't have to quote as bracket is not the start of the value and not conflict with yaml
    - name: multple_render_var_level3_with_expand2
      value: multple-render-var-> {{.b2}}
      expand: 2
    - name: multple_render_var_level3_with_expand3
      value: multple-render-var-> {{.b2}}
      expand: 3
    - name: multple_render_var_level3_with_expand4
      value: multple-render-var-> {{.b2}}
      expand: 4
    - name: multple_render_var_level5
      value: multple-render-var-> {{.a1}}
      expand: 5
    #  - name: invalid-name
    #    value: multple-render-var-> {{.a1}}
    tasks:
    - name: task
      task:
      - func: shell
        do:
        - echo "student=>{{.student}}"
        - echo "a1=> a1->{{.b2}}"
        - echo "from->{{.from}}"
        - echo "sex->{{.sex}}"
        - echo "dependon_vars->{{.dependon_vars}}"
        - echo "dependon_var_and_dvar->{{.dependon_var_and_dvar}}"
        - echo "multple_render_var_level3->{{.multple_render_var_level3}}"
        - echo "multple_render_var_level4->{{.multple_render_var_level4}}"
    
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 -> c0023
                 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/c0023
    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,
      "a1": "a1->{{.b2}}",
      "dependon_var_and_dvar": "Tom-Male",
      "dependon_vars": "Male",
      "c3": "c3->{{.d4}}",
      "multple_render_var_level5": "multple-render-var-> a1->b2->c3->d4->Tom",
      "d4": "d4->{{.student}}",
      "school": "Sydney Grammar",
      "multple_render_var_level3_with_expand3": "multple-render-var-> b2->c3->d4->{{.student}}",
      "multple_render_var_level3": "multple-render-var-> b2->{{.c3}}",
      "from": "Sydney Grammar",
      "multple_render_var_level3_with_expand4": "multple-render-var-> b2->c3->d4->Tom",
      "student": "Tom",
      "sex": "Male",
      "b2": "b2->{{.c3}}",
      "gender": "Male",
      "multple_render_var_level3_with_expand2": "multple-render-var-> b2->c3->{{.d4}}"
    })
    
    cmd( 1):
    echo "student=>{{.student}}"
    
    -
    student=>Tom
    
    -
     .. ok
    cmd( 2):
    echo "a1=> a1->{{.b2}}"
    
    -
    a1=> a1->b2->{{.c3}}
    
    -
     .. ok
    cmd( 3):
    echo "from->{{.from}}"
    
    -
    from->Sydney Grammar
    
    -
     .. ok
    cmd( 4):
    echo "sex->{{.sex}}"
    
    -
    sex->Male
    
    -
     .. ok
    cmd( 5):
    echo "dependon_vars->{{.dependon_vars}}"
    
    -
    dependon_vars->Male
    
    -
     .. ok
    cmd( 6):
    echo "dependon_var_and_dvar->{{.dependon_var_and_dvar}}"
    
    -
    dependon_var_and_dvar->Tom-Male
    
    -
     .. ok
    cmd( 7):
    echo "multple_render_var_level3->{{.multple_render_var_level3}}"
    
    -
    multple_render_var_level3->multple-render-var-> b2->{{.c3}}
    
    -
     .. ok
    cmd( 8):
    echo "multple_render_var_level4->{{.multple_render_var_level4}}"
    
    -
    multple_render_var_level4-><no value>
    
    -
     .. ok
    . ok
    
Logs with different verbose level
Raw logs with different verbose level