Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env access for sh vars #1742

Open
titpetric opened this issue Aug 8, 2024 · 1 comment
Open

Env access for sh vars #1742

titpetric opened this issue Aug 8, 2024 · 1 comment
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@titpetric
Copy link

I declared global env in a taskfile like so:

---
version: "3"

env:
  DB_DRIVER: mysql
  DB_DSN: "etl:etl@tcp(localhost:3306)/etl"

tasks:
  default:
    desc: "Fill repos with details"
    vars:
      repos:
        sh: env | grep DB_ || true
    cmds:
      - env | grep DB || true
      - for: { var: repos, as: repo, split: "\n" }
        silent: true
        cmd: echo "X{{.repo}}"

The expected output of this would be:

DB_DRIVER=mysql
DB_DSN=etl:etl@tcp(localhost:3306)/etl
XDB_DRIVER=mysql
XDB_DSN=etl:etl@tcp(localhost:3306)/etl

Actual output of this is:

DB_DRIVER=mysql
DB_DSN=etl:etl@tcp(localhost:3306)/etl
X

Seems the vars sh are not picking up the taskfile env which would be my expectation...

@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Aug 8, 2024
@nierob
Copy link

nierob commented Aug 30, 2024

I have stumbled over that too:

~/d/tmp►batcat Taskfile.yml                                                                                                                            4.526s 14:52
───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: Taskfile.yml
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ version: "3"
   2   │
   3   │ env:
   4   │   GLOBAL_NAME: "foo"
   5   │
   6   │ tasks:
   7   │   hello:
   8   │     cmds:
   9   │       - echo "$GLOBAL_NAME"
  10   │       - echo "$INDIRECT_NAME"
  11   │       - echo "$ENV_NAME"
  12   │     env:
  13   │       INDIRECT_NAME:
  14   │         sh: echo "$GLOBAL_NAME"
  15   │       ENV_NAME:
  16   │         sh: echo "bar"
  17   │
  18   │
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
~/d/tmp►task hello                                                                                                                                            14:52
task: [hello] echo "$GLOBAL_NAME"
foo
task: [hello] echo "$INDIRECT_NAME"

task: [hello] echo "$ENV_NAME"
bar

It looks like sh initialization does not get globally set env

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

3 participants