Docs: Environment Helpers

Documentation

Environment Helpers

Reading the worker's environment, finding programs, and logging.

env

env(name) reads a variable from the worker's explicit environment and returns an empty string when it is not set. Recipes don't change the worker's environment: give a command its own variables with the env option of exec, exec_checked or exec_output (see Command Helpers).

Rhai
let path = env("PATH");
exec_checked("make", [], #{ cwd: src.source, env: #{ CC: "clang", CFLAGS: "-O2" } });

command_exists

command_exists(name) is true if the program is on the domain's PATH, which includes the executables of the recipe's dependencies.

Rhai
if !command_exists("cargo") {
    throw "this recipe needs cargo in the image or a build dependency";
}

Logging

All diagnostics go to stderr, so stdout carries only the final JSON.

Rhai
log("Building kernel...");             // [recipe] message
warn("Config changed, rebuilding");    // [recipe:warn] message
debug("source: " + src.source);           // with the recipe's source position
print("plain line");                   // stderr as well