Skip to content

New env attribute doesn't accept variables for values #3166

@bedlamzd

Description

@bedlamzd

I have the following problem, when trying to write commands to run tests for the http client library. The API needs credentials, which it pulls from environment variables. Usually I run tests against local docker service, using default credentials in the environment/baked into tests. But I also want to run it against my proper deployed instance, which means providing proper credentials, overriding default ones.

In the latest release there was env attribute added, which looks like exactly what I need, but turns out it doesn't accept variables for values. This is a bit surprising to me, because the alternative $PARAMETER syntax does accept variables.

Here's an example of what I'm trying to do

username := env("REAL_USERNAME", "")
password := env("REAL_PASSWORD", "")

# here I want to override envvars
[env("USERNAME", username)]
[env("PASSWORD", password)]
test-real-service *args:
    test {{ args }}

docker-up:
    ...

# uses default credentials from env
test-docker *args: docker-up
    test {{ args }}

Note that exporting them globally doesn't fix the issue, because I don't want them to be visible in test-docker recipe, only in test-real-service.

Previously I'd use export syntax for recipe parameters:

recipe $PASSWORD=env("REAL_PASSWORD"):
    command

Which is fine most of the time, but here I want to forward arguments to the command, which makes it impractical.

While I could run something like PASSWORD=$REAL_PASSWORD just test, I don't want to do that each time + in my opinion that's what just is for.

And the last option would be something like

password := env("REAL_PASSWORD", "")
recipe *args:
    PASSWORD={{password}} test

But that's icky, as it'll substitute and print the password. Of course it can be muted, but still doesn't feel like a great solution, especially when I want to see exact commands that run.

I guess that the original problem due to attributes not accepting variables in general? Maybe there's a different preferred way to do that, that I missed?

That said, really great tool, thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions