xx
.md

env_set

env_set returns a dependency that replaces an environment variable with one value. It changes only tasks that use the dependency. Values are stored unchanged; use path_make_absolute when a path should be resolved from the project root.

Arguments

ArgumentRequiredDescription
keyYesEnvironment variable name to set.
valueYesString value assigned to the variable.

Examples

Set one variable

load("@os@1", "env_set", "os_run")

os_run(("tools/check",), deps=[env_set("MODE", "check")])

Build a reusable environment

load("@[email protected]", "go")
load("@os@1", "env_set", "os_run")

release_env = (
    env_set("MODE", "release") +
    env_set("CGO_ENABLED", "0")
)

os_run(("go", "build", "./cmd/server"), deps=[go, release_env])
os_run(("go", "test", "./..."), deps=[go, release_env])