T
Task2mo ago
Beinish

Boolean value keeps evaluating as false

Hello everyone, I'm trying to do something like this:
vars:
with_elastic:
sh: |
echo "{{.CLI_ARGS}}" | grep -q "elastic" && echo true || echo false
repos:
- name: devops-config
branch: "main"
clone: true
- name: "dev-deps"
branch: "main"
clone: true
- name: "elastic-data"
branch: "main"
clone: '{{.with_elastic}}'

reusable-checkout-repo:
desc: "Reusable task to clone a repo"
label: "checkout-{{.repo_name}}"
internal: true
silent: true
dir: "{{.tmp_dir}}"
status:
- test -d {{.repo_name}}
cmds:
- |
echo {{.repo_name}}:{{.clone}}

checkout-repos:
desc: "Checkout dev-deps and devops-config repos"
dir: "{{.tmp_dir}}"
# internal: true
silent: true
cmds:
- |
echo "CLI Args: {{.CLI_ARGS}}"
echo "{{.CLI_ARGS}}" | grep -q "elastic" && echo true || echo false
- for: { var: repos, as: repo }
task: reusable-checkout-repo
vars: { repo_name: "{{.repo.name}}", repo_branch: "{{.repo.branch}}", clone: "{{.repo.clone}}" }
vars:
with_elastic:
sh: |
echo "{{.CLI_ARGS}}" | grep -q "elastic" && echo true || echo false
repos:
- name: devops-config
branch: "main"
clone: true
- name: "dev-deps"
branch: "main"
clone: true
- name: "elastic-data"
branch: "main"
clone: '{{.with_elastic}}'

reusable-checkout-repo:
desc: "Reusable task to clone a repo"
label: "checkout-{{.repo_name}}"
internal: true
silent: true
dir: "{{.tmp_dir}}"
status:
- test -d {{.repo_name}}
cmds:
- |
echo {{.repo_name}}:{{.clone}}

checkout-repos:
desc: "Checkout dev-deps and devops-config repos"
dir: "{{.tmp_dir}}"
# internal: true
silent: true
cmds:
- |
echo "CLI Args: {{.CLI_ARGS}}"
echo "{{.CLI_ARGS}}" | grep -q "elastic" && echo true || echo false
- for: { var: repos, as: repo }
task: reusable-checkout-repo
vars: { repo_name: "{{.repo.name}}", repo_branch: "{{.repo.branch}}", clone: "{{.repo.clone}}" }
The end goal is to clone a repo if a specific argument was passed to the CLI. Testing it with:
task checkout-repos -- elastic
task checkout-repos -- elastic
Gives me:
CLI Args: elastic
true
devops-config:true
dev-deps:true
elastic-data:false
CLI Args: elastic
true
devops-config:true
dev-deps:true
elastic-data:false
So the actual grep that I pass in the sh of with_elastic evaluates to be true, while the final result of calling {{.with_elastic}} is false. Why? And how do I do it correctly?
1 Reply
adamdicarlo
adamdicarlo2mo ago
did you get this solved? I don't see what populates {{.with_elastic}}
Want results from more Discord servers?
Add your server