jdx/mise

task-specific env vars unavailable in templates but accessible as shell vars

bartsmykla opened this issue · 0 comments

Describe the bug
Environment variables defined in TOML tasks are not accessible in templates via the env object or the get_env function, but they are available as regular Bash environment variables. For example, when using the following mise.toml:

[env]
FOO = "foo"

[tasks.foo]
env.BAR = "bar"

run = """
printf '$BAR: %s\n' $BAR
echo "{% raw %}{{ env.BAR }}{% endraw %}: {{ env.BAR | default(value='undefined') }}"
"""

depends_post = [
    "debug:env:clean"
]

[tasks."debug:env:clean"]
run = """
cat <<'EOF' | sed -e "s|$HOME||g" | jq '.PATH = "..."'
{{ env | json_encode() }}
EOF
"""

When I run mise run foo, the results are as follows:

[foo] $ printf '$BAR: %s
$BAR: bar
{{ env.BAR }}: undefined
[debug:env:clean] $ cat <<'EOF' | sed -e "s|$HOME||g" | jq '.PATH = "..."'
{
  "FOO": "foo",
  "PATH": "..."
}

The variable BAR defined in the task's env is visible to the shell as a regular environment variable but is not accessible in the template via {{ env.BAR }} or {{ get_env('BAR') }}.

To Reproduce

  1. Use the mise.toml configuration provided above.
  2. Run mise run foo.
  3. Observe that {{ env.BAR }} and {{ get_env('BAR') }} in the run template are not rendered and default to undefined, while $BAR is correctly available as a Bash environment variable.

Expected behavior
Environment variables defined in a task's env should be accessible in templates using env.BAR or get_env('BAR').

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