tmp file

This shows how to create a tmp file with content

params: * reg: register the file path to a name, so you can reference the file using this reg name * content: the content of the file to be created

Note: You will have to manage to delete or clean up the tmp file in either step finally or task finally if you wish to

Demo

source

Main task yaml file
    tasks:
    - name: task
      task:
      - func: cmd
        do:
        - name: tmpFile
          cmd:
            reg: myfile
            content: hello, world
        - name: print
          cmd: 'filename: {{.myfile}}'
        - name: readFile
          cmd:
            filename: '{{.myfile}}'
            reg: my_file_content
        - name: print
          cmd: 'file content: {{.my_file_content}}'
        finally:
        - func: shell
          do: 'cat {{.myfile}}'
        - func: shell
          desc: |
            this shows you delete the tmp file in step finally
          do: 'rm -f {{.myfile}}'
        - func: shell
          do: 'cat {{.myfile}}'
          flags: [ignoreError]
      finally:
      - func: shell
        desc: |
          this shows you delete the tmp file in task finally
          this is deactivated
          just for reference
        dox: 'rm -f {{.myfile}}'
      - func: shell
        do: 'cat {{.myfile}}'
        flags: [ignoreError]
    
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 -> c0195
                 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/c0195
    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
    })
    
    ~SubStep1: [tmpFile:  ]
    tmp file handler: myfile
    ~SubStep2: [print:  ]
    filename: /tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157
    ~SubStep3: [readFile:  ]
    ~SubStep4: [print:  ]
    file content: hello, world
    Step Finally:
    -Step1:
    self: final context exec vars:
    
    (*core.Cache)({
      "my_file_content": "hello, world",
      "up_runtime_task_layer_number": 0,
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>),
      "myfile": "/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157"
    })
    
    cmd( 1):
    cat {{.myfile}}
    
    -
    hello, world
    -
     .. ok
    . ok
    -Step2: [
    this shows you delete the tmp file in step finally
    ]
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>),
      "myfile": "/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157",
      "my_file_content": "hello, world",
      "last_result": (*utils.ExecResult)({
        Cmd: "cat /tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157",
        Code: 0,
        Output: "hello, world",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0
    })
    
    cmd( 1):
    rm -f {{.myfile}}
    
    -
    
    -
     .. ok
    . ok
    -Step3:
    self: final context exec vars:
    
    (*core.Cache)({
      "myfile": "/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157",
      "my_file_content": "hello, world",
      "last_result": (*utils.ExecResult)({
        Cmd: "rm -f /tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157",
        Code: 0,
        Output: "",
        ErrMsg: ""
      }),
      "up_runtime_task_layer_number": 0,
      "up_runtime_shell_exec_result": (*utils.ExecResult)(<nil>)
    })
    
    cmd( 1):
    cat {{.myfile}}
    
    -
    cat: can't open '/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157': No such file or directory
    
    -
     .. failed(suppressed if it is not the last step)
     WARN: [ignoreError:] - [Error ignored!!!]
    task Finally:
    Step1: [
    this shows you delete the tmp file in task finally
    this is deactivated
    just for reference
    ]
     WARN: [*] - [Step is deactivated!]
    Step2:
    self: final context exec vars:
    
    (*core.Cache)({
      "up_runtime_task_layer_number": 0,
      "my_file_content": "hello, world",
      "last_result": (*utils.ExecResult)(<nil>),
      "myfile": "/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157"
    })
    
    cmd( 1):
    cat {{.myfile}}
    
    -
    cat: can't open '/tmp/BpLnfgDsc2WD8F2qNfHK5a84891123157': No such file or directory
    
    -
     .. failed(suppressed if it is not the last step)
     WARN: [ignoreError:] - [Error ignored!!!]
    
Logs with different verbose level
Raw logs with different verbose level