Skip to content

Idea: Consider having functions to access variables and envs #1065

@andreynering

Description

This is an idea for the next major version, and would be a breaking change.

Nowadays both variables and envs are accessed as Go template values, like this:

{{.MY_VARIABLE}}
{{.MY_ENV}}

This have a couple of drawbacks:

  1. Variables need to be declared in an specific order if you want to include one into another:
FOO: foo
FOOBAR: '{{.FOO}}bar'
FOOBARBAZ: '{{.FOOBAR}}baz'
  1. Variables and envs are mixed, and this often generate a bit of confusion to users.

  2. Shell variables are always computed, even when they are not being used.

    • We also currently cache them, which can be annoying if the user want to calculate it again on every call. On the current implementation removing the cache would not be a good idea, though, because it would calculate these multiple times unnecessarily.

This proposal to have two template functions called var and env to access these values:

MY_VARIABLE: '{{var "MY_VARIABLE"}}'
MY_ENV: '{{env "MY_ENV"}}'

As part of these proposal, environment variables would stop being added to variables, so you need to really call env if you want an env.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions