datapath

Other than use datakey as data source for dvar rending, you can use datapath to reference to a varname and a sub element of a var in global runtime scope

How to use

  • datapath: format is like a.b.c(name=fr*).value, following the yq path format:

    1. ‘a.b.c’
    2. ‘a.*.c’
    3. ‘a.**.c’
    4. ‘a.(child.subchild==co*).c’
    5. ‘a.array[0].blah’
    6. ‘a.array[*].blah’

Relavant

templating using datakey and datapath

references

query and yq datapath

query details

references

Demo

source

Main task yaml file
    vars:
      student:
        name: Tom
        gender: Male
        school: Sydney Grammar
      nsw:
        sydney:
          sgschool:
            student:
              name: Tom
              gender: Male
              school: Sydney Grammar
      aaa: aaa
      datapointer: student
    tasks:
    - name: task
      task:
      - func: cmd
        desc: use sub element of an var as context to render values
        dvars:
        - name: student_info
          value: 'my name is:{{.name}} and I am in {{.school}}'
          datapath: nsw.sydney.sgschool.student
          flags: [vvv]
        do:
        - name: print
          cmd: '{{.student_info}}'
    
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 -> c0098
                 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/c0098
    module: [self], instance id: [dev], exec profile: []
    profile -  envVars:
    
    (*core.Cache)({
    })
    
    Task1: [task ==> task:  ]
    -Step1: [: use sub element of an var as context to render values ]
    dvar> student_info:
    "my name is:<no value> and I am in <no value>"
    
    -
    my name is:<no value> and I am in <no value>
    self: final context exec vars:
    
    (*core.Cache)({
      "nsw": {
        "sydney": {
          "sgschool": {
            "student": {
              "gender": "Male",
              "school": "Sydney Grammar",
              "name": "Tom"
            }
          }
        }
      },
      "aaa": "aaa",
      "datapointer": "student",
      "up_runtime_task_layer_number": 0,
      "student_info": "my name is:<no value> and I am in <no value>",
      "student": {
        "school": "Sydney Grammar",
        "name": "Tom",
        "gender": "Male"
      }
    })
    
    ~SubStep1: [print:  ]
    my name is:<no value> and I am in <no value>
    
Logs with different verbose level
Raw logs with different verbose level

Other references: