From dd6be011609937477516344d217a24aadf92fcd2 Mon Sep 17 00:00:00 2001 From: Sascha Roloff Date: Thu, 8 May 2025 13:39:53 +0200 Subject: Invocation logging: add new field context variables It allows to specify a list of environment variables, which are captured at invocation time and stored as key-value pairs in the metadata file. This allows to get some information about the invocation context such as username, merge-request ID or source branch (on a CI runner), or others. --- src/other_tools/just_mr/launch.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/other_tools/just_mr/launch.cpp') diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp index ca21e268..dc861c11 100644 --- a/src/other_tools/just_mr/launch.cpp +++ b/src/other_tools/just_mr/launch.cpp @@ -371,6 +371,15 @@ auto CallJust(std::optional const& config_file, meta["configuration"] = mr_config_pair->second; } meta["cmdline"] = cmd; + if (not invocation_log.context_vars.empty()) { + auto context = nlohmann::json::object(); + for (auto const& env_var : invocation_log.context_vars) { + auto* env_value = std::getenv(env_var.c_str()); + context[env_var] = + env_value != nullptr ? env_value : nlohmann::json{}; + } + meta["context"] = context; + } // "configuration" -- the blob-identifier of the multi-repo // configuration auto file_name = *log_dir / *invocation_log.metadata; -- cgit v1.2.3