pbitty
pbitty
TTask
Created by cloudneopren on 9/10/2024 in #help
yaml formatted data
I think your issue is that the top-level type in file.json is not a map but an array. If I use the following file.json:
{
"cosign":{"pkm":"arkade"},
"flux":{"pkm":"go"},
"kubectl":{"pkm":"arkade"}
}
{
"cosign":{"pkm":"arkade"},
"flux":{"pkm":"go"},
"kubectl":{"pkm":"arkade"}
}
And the following Taskfile:
version: '3'

tasks:
default:
vars:
FILE:
sh: cat file.json
ARRAY:
ref: "fromJson .FILE"
cmds:
- for:
var: ARRAY
cmd: |
echo '{{.KEY}}: {{.ITEM.pkm}}'
version: '3'

tasks:
default:
vars:
FILE:
sh: cat file.json
ARRAY:
ref: "fromJson .FILE"
cmds:
- for:
var: ARRAY
cmd: |
echo '{{.KEY}}: {{.ITEM.pkm}}'
I get the output:
task: [default] echo 'cosign: arkade'

cosign: arkade
task: [default] echo 'flux: go'

flux: go
task: [default] echo 'kubectl: arkade'

kubectl: arkade
task: [default] echo 'cosign: arkade'

cosign: arkade
task: [default] echo 'flux: go'

flux: go
task: [default] echo 'kubectl: arkade'

kubectl: arkade
Would something like that work for your use-case?
6 replies
TTask
Created by cloudneopren on 9/10/2024 in #help
yaml formatted data
@cloudneopren , I want to make sure I understand your question. The example in the docs shows:
tasks:
foo:
vars:
ARRAY: [1, 2, 3]
tasks:
foo:
vars:
ARRAY: [1, 2, 3]
Are you asking about whether you can format the array like this?
tasks:
foo:
vars:
ARRAY:
- 1
- 2
- 3
tasks:
foo:
vars:
ARRAY:
- 1
- 2
- 3
If so, yes. Both formats are valid YAML. If that is not your question, could you expand on it?
6 replies