Beinish
Beinish
TTask
Created by Beinish on 11/3/2024 in #help
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 replies