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 vars defined earlier fail to render in subsequent env var templates #3755

Closed
bartsmykla opened this issue Dec 21, 2024 · 2 comments · Fixed by #3758
Closed

env vars defined earlier fail to render in subsequent env var templates #3755

bartsmykla opened this issue Dec 21, 2024 · 2 comments · Fixed by #3758
Labels

Comments

@bartsmykla
Copy link

Describe the bug
According to the documentation (https://mise.jdx.dev/environments/#using-env-vars-in-other-env-vars), it should be possible to use env vars defined earlier in subsequent env vars. However, when I attempt the following:

[env]
A = "a"
B = "{{ env.B }}"

I receive the following error:

mise ERROR failed to parse template: '{{ env.B }}'
mise ERROR Failed to render '__tera_one_off'
mise ERROR Variable `env.B` not found in context while rendering '__tera_one_off'
mise ERROR Run with --verbose or MISE_VERBOSE=1 for more information

This prevents me from using a variable from a script in a PATH definition. For example:

[env]
_.source = ".mise/env.sh"
_.path = [
    "{{ env.__GENERATE_TOOLS_DIR }}",
]

To Reproduce

  1. Define environment variables as shown in the example above.
  2. Run mise and observe the error output.

Expected behavior
I expected the environment variables defined earlier to be usable in subsequent env vars without causing errors.

mise doctor output

version: 2024.12.15 macos-arm64 (0d37f33 2024-12-19)
activated: yes
shims_on_path: no

build_info:
Target: aarch64-apple-darwin
Features: DEFAULT, NATIVE_TLS, OPENSSL
Built: Thu, 19 Dec 2024 18:51:18 +0000
Rust Version: rustc 1.83.0 (90b35a623 2024-11-26)
Profile: release

shell:
/opt/homebrew/bin/fish
fish, version 3.7.1

dirs:
cache: ~/Library/Caches/mise
config: ~/.config/mise
data: ~/.local/share/mise
shims: ~/.local/share/mise/shims
state: ~/.local/state/mise

config_files:
~/.config/mise/config.toml
~/project/mise.toml

backends:
aqua
asdf
cargo
core
gem
go
npm
pipx
spm
ubi
vfox

plugins:
clang-format           git@github.com:higebu/asdf-llvm.git#c527fd9
kube-controller-tools  git@github.com:jimmidyson/asdf-kube-controller-tools.git#37526dc
oapi-codegen           git@github.com:dylanrayboss/asdf-oapi-codegen.git#a988840

toolset:
aqua:GoogleContainerTools/container-structure-test@1.19.3
aqua:etcd-io/etcd@3.5.17
aqua:golangci/golangci-lint@1.62.0
aqua:helm/helm@3.16.4
aqua:jqlang/jq@1.7.1
aqua:koalaman/shellcheck@0.10.0
aqua:kubernetes-sigs/kubebuilder@4.3.1
aqua:kubernetes/kubectl@1.32.0
aqua:norwoodj/helm-docs@1.11.0
aqua:protocolbuffers/protobuf-go/protoc-gen-go@1.28.1
aqua:protocolbuffers/protobuf/protoc@3.20.0
aqua:stackrox/kube-linter@0.6.5
asdf:kube-controller-tools@0.16.5
asdf:oapi-codegen@2.4.1
core:go@1.23.4
go:github.com/envoyproxy/protoc-gen-validate@v1.1.0
go:github.com/google/osv-scanner/cmd/osv-scanner@1.9.1
go:github.com/onsi/ginkgo/v2/ginkgo@2.22.0
go:github.com/pubg/protoc-gen-jsonschema@0.6.2
go:google.golang.org/grpc/cmd/protoc-gen-go-grpc@1.1.0
ubi:bartsmykla/clang-tools-static-binaries@foo
ubi:hadolint/hadolint@2.12.0
ubi:jdx/usage@1.7.2
ubi:k3d-io/k3d@5.7.5
ubi:kubernetes-sigs/kind@0.26.0
ubi:mikefarah/yq@4.30.8
@bartsmykla bartsmykla added the bug label Dec 21, 2024
@jdx
Copy link
Owner

jdx commented Dec 21, 2024

don't you mean B = "{{env.A}}"? that works for me

@bartsmykla
Copy link
Author

@jdx You’re right - I made a mistake. The A and B examples were oversimplified and by my mistake actually were incorrect. My actual problem happens with the following setup:

In my mise.toml file:

[env]
_.source = { path = ".mise/env.sh", tools = true }
_.path = [
    "{{ env.__GENERATE_TOOLS_DIR }}",
]

And .mise/env.sh contains:

#!/usr/bin/env bash

set -Eeuo pipefail

export __GENERATE_TOOLS_DIR="/foo"

When I run this, I get the following error:

[debug:env] ERROR task failed
mise ERROR failed to parse template: '{{ env.__GENERATE_TOOLS_DIR }}'
mise ERROR Failed to render '__tera_one_off'
mise ERROR Variable `env.__GENERATE_TOOLS_DIR` not found in context while rendering '__tera_one_off'
mise ERROR Run with --verbose or MISE_VERBOSE=1 for more information

It seems like the variable __GENERATE_TOOLS_DIR is not being passed into the template context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants