silent the shell execution
You can use the flag silent to silent the shell execution, or silent-x to silent the sub step of the shell execution
Demo
source
Main task yaml file
tasks:
- name: task
task:
- func: shell
desc: the output of cat would be silent
vars:
msg: |
hello, world
thank you
hello tom
good buy
do:
- echo """{{.msg}}""" > /tmp/msg
- cat /tmp/msg
flags:
- silent
- func: cmd
desc: explicitly show the the shell exec result
do:
- name: print
cmd: '{{.last_result.Output}}'
- func: shell
desc: the silent will not affect output of failed shell execution
vars:
msg: |
hello, world
thank you
hello tom
good buy
do:
- |
>&2 echo "encountering an error"
exit -1
flags:
- silent
- ignoreError
- func: shell
desc: |
silient only one sub step but not all
in this case, it will make sub step 1 msg1 silent but not the msg2
vars:
msg1: sub step1
msg2: sub step2
do:
- echo """{{.msg1}}"""
- echo """{{.msg2}}"""
flags:
- silent-1
- func: shell
desc: |
silient only one sub step but not all
in this case, it will make sub step 2 msg2 silent but not the msg1
vars:
msg1: sub step1
msg2: sub step2
do:
- echo """{{.msg1}}"""
- echo """{{.msg2}}"""
flags:
- silent-2
- func: shell
desc: |
if there are combined flags of silent and silent-x, silent will take priority, then there will be no output for all of the sub steps
vars:
msg1: sub step1
msg2: sub step2
do:
- echo """{{.msg1}}"""
- echo """{{.msg2}}"""
flags:
- silent-1
- silent
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 -> c0180
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/c0180
module: [self], instance id: [dev], exec profile: []
profile - envVars:
(*core.Cache)({
})
Task1: [task ==> task: ]
-Step1: [: the output of cat would be silent ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"msg": "hello, world\nthank you\nhello tom\ngood buy\n"
})
cmd( 1):
echo """{{.msg}}""" > /tmp/msg
-
-
.. ok
cmd( 2):
cat /tmp/msg
-
-
.. ok
. ok
-Step2: [: explicitly show the the shell exec result ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"last_result": (*utils.ExecResult)({
Cmd: "cat /tmp/msg",
Code: 0,
Output: "hello, world\nthank you\nhello tom\ngood buy",
ErrMsg: ""
})
})
~SubStep1: [print: ]
hello, world
thank you
hello tom
good buy
-Step3: [: the silent will not affect output of failed shell execution ]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"msg": "hello, world\nthank you\nhello tom\ngood buy\n",
"last_result": (*utils.ExecResult)({
Cmd: "cat /tmp/msg",
Code: 0,
Output: "hello, world\nthank you\nhello tom\ngood buy",
ErrMsg: ""
})
})
cmd( 1):
>&2 echo "encountering an error"
exit -1
-
encountering an error
/bin/sh: exit: line 2: Illegal number: -1
-
.. failed(suppressed if it is not the last step)
WARN: [ignoreError:] - [Error ignored!!!]
-Step4: [
silient only one sub step but not all
in this case, it will make sub step 1 msg1 silent but not the msg2
]
self: final context exec vars:
(*core.Cache)({
"last_result": (*utils.ExecResult)({
Cmd: ">&2 echo \"encountering an error\"\nexit -1\n",
Code: 2,
Output: "",
ErrMsg: "encountering an error\n/bin/sh: exit: line 2: Illegal number: -1\n"
}),
"up_runtime_task_layer_number": 0,
"msg1": "sub step1",
"msg2": "sub step2"
})
cmd( 1):
echo """{{.msg1}}"""
-
-
.. ok
cmd( 2):
echo """{{.msg2}}"""
-
sub step2
-
.. ok
. ok
-Step5: [
silient only one sub step but not all
in this case, it will make sub step 2 msg2 silent but not the msg1
]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"msg1": "sub step1",
"msg2": "sub step2",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"\"\"sub step2\"\"\"",
Code: 0,
Output: "sub step2",
ErrMsg: ""
})
})
cmd( 1):
echo """{{.msg1}}"""
-
sub step1
-
.. ok
cmd( 2):
echo """{{.msg2}}"""
-
-
.. ok
. ok
-Step6: [
if there are combined flags of silent and silent-x, silent will take priority, then there will be no output for all of the sub steps
]
self: final context exec vars:
(*core.Cache)({
"up_runtime_task_layer_number": 0,
"msg1": "sub step1",
"msg2": "sub step2",
"last_result": (*utils.ExecResult)({
Cmd: "echo \"\"\"sub step2\"\"\"",
Code: 0,
Output: "sub step2",
ErrMsg: ""
})
})
cmd( 1):
echo """{{.msg1}}"""
-
-
.. ok
cmd( 2):
echo """{{.msg2}}"""
-
-
.. ok
. ok
Logs with different verbose level
Raw logs with different verbose level