Problem:
The directive label's function is to allow a task to output a
text string, other than the task name when the task is executed.
In the official documentation states that label:
'Overrides the name of the task in the output when a task is
run. Supports variables.'
If the label directive is set for a task, say to Hello
with label: 'Hello' and the directive output: prefixed is
also included in the Taskfile, the output is not as expected.
Further, the outcome is the same if the label text is set
dynamically using a Task variable.
See the section 'Analysis' below.
Test Taskfile.yml
The Taskfile below contains two tasks one where label is a static
string and one task where the label is from a dynamically loaded
task variable.
version: '3'
output: prefixed
vars:
VERSION: '0.2'
BACKUP_TIME:
sh: date +"%Y-%m-%d_%H:%M:%S"
SYSTEM_ID:
sh: |
hostname
BACKUP_ID: '{{.SYSTEM_ID}}_{{.BACKUP_TIME}}'
tasks:
default:
# Predefined string for label
label: 'Hello'
desc: Display Task variables
cmds:
- |
echo "HostName:"{{.SYSTEM_ID}}
echo "Backup_Time:"{{.BACKUP_TIME}}
echo "Backup ID:" {{.SYSTEM_ID }}{{.BACKUP_TIME}}
echo "Version:" {{.VERSION}}
dynamic:
# Dynamic string for label
label: '{{.BACKUP_ID}}'
desc: Display Task variables with label set dynamically
cmds:
- |
echo "HostName:"{{.SYSTEM_ID}}
echo "Backup_Time:"{{.BACKUP_TIME}}
echo "Backup ID:" {{.SYSTEM_ID }}{{.BACKUP_TIME}}
echo "Backup ID 2:" {{.VERSION}}
Output Generated and expected
Output generated from the task default:
task: [Hello] echo "HostName:"MBP.local
echo "Backup_Time:"2022-11-14_13:41:47
echo "Backup ID:" MBP.local2022-11-14_13:41:47
echo "Version:" 0.2
[default] HostName:MBP.local
[default] Backup_Time:2022-11-14_13:41:47
[default] Backup ID: MBP.local2022-11-14_13:41:47
[default] Version: 0.2
Output expected from the task default:
task: [Hello] echo "HostName:"MBP.local
echo "Backup_Time:"2022-11-14_13:41:47
echo "Backup ID:" MBP.local2022-11-14_13:41:47
echo "Version:" 0.2
[Hello] HostName:MBP.local
[Hello] Backup_Time:2022-11-14_13:41:47
[Hello] Backup ID: MBP.local2022-11-14_13:41:47
[Hello] Version: 0.2
Output generated from the task dynamic:
task: [MBP.local_2022-11-14_13:42:39] echo "HostName:"MBP.local
echo "Backup_Time:"2022-11-14_13:42:39
echo "Backup ID:" MBP.local2022-11-14_13:42:39
echo "Backup ID 2:" 0.2
[dynamic] HostName:MBP.local
[dynamic] Backup_Time:2022-11-14_13:42:39
[dynamic] Backup ID: MBP.local2022-11-14_13:42:39
[dynamic] Backup ID 2: 0.2
Output expected from the task dynamic:
task: [MBP.local_2022-11-14_13:42:39] echo "HostName:"MBP.local
echo "Backup_Time:"2022-11-14_13:42:39
echo "Backup ID:" MBP.local2022-11-14_13:42:39
echo "Backup ID 2:" 0.2
[MBP.local_2022-11-14_13:42:39] HostName:MBP.local
[MBP.local_2022-11-14_13:42:39] Backup_Time:2022-11-14_13:42:39
[MBP.local_2022-11-14_13:42:39] Backup ID: MBP.local2022-11-14_13:42:39
[MBP.local_2022-11-14_13:42:39] Backup ID 2: 0.2
Analysis
The label directive works for both static and dynamic
values and does label the first instance of the task name as
seen in line 1 of both sets of output.
The label directive does not output the substitute name
in the output strings from the echo commands, as requested by
output prefixed directive. The output reverts to the
task name.
- Task Version 3.17
- Operating System: OS X Version Monterey 12.6
Problem:
The directive
label's function is to allow a task to output atext string, other than the task name when the task is executed.
In the official documentation states that label:
'Overrides the name of the task in the output when a task is
run. Supports variables.'
If the
labeldirective is set for a task, say toHellowith
label: 'Hello'and the directiveoutput: prefixedisalso included in the Taskfile, the output is not as expected.
Further, the outcome is the same if the label text is set
dynamically using a Task variable.
See the section 'Analysis' below.
Test
Taskfile.ymlThe Taskfile below contains two tasks one where label is a static
string and one task where the label is from a dynamically loaded
task variable.
Output Generated and expected
Output generated from the task default:
Output expected from the task default:
Output generated from the task
dynamic:Output expected from the task
dynamic:Analysis
The
labeldirective works for both static and dynamicvalues and does label the first instance of the task name as
seen in line 1 of both sets of output.
The
labeldirective does not output the substitute namein the output strings from the echo commands, as requested by
output prefixeddirective. The output reverts to thetask name.