summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/just-mrrc.5.md6
-rw-r--r--share/man/just-profile.5.md5
-rw-r--r--src/other_tools/just_mr/cli.hpp1
-rw-r--r--src/other_tools/just_mr/launch.cpp9
-rw-r--r--src/other_tools/just_mr/rc.cpp10
5 files changed, 31 insertions, 0 deletions
diff --git a/share/man/just-mrrc.5.md b/share/man/just-mrrc.5.md
index 956d8ad3..662717b7 100644
--- a/share/man/just-mrrc.5.md
+++ b/share/man/just-mrrc.5.md
@@ -183,6 +183,12 @@ The just-mrrc is given by a JSON object.
directory the metadata file should be stored. If not given,
no metadata file will be written. See **`just-profile`**(5) for
details of the format.
+ - *`"context variables"`* An optional list of environment variables,
+ which are captured at invocation time and stored as key-value pairs
+ in the metadata file. These variables do not affect the build in
+ any way. Instead, they are supposed to provide useful context
+ information about the invocation like username, merge-request ID or
+ source branch.
- *`"--dump-graph"`* A file name specifying the file in
the invocation-log directory for an invocation-specific
`--dump-graph` option.
diff --git a/share/man/just-profile.5.md b/share/man/just-profile.5.md
index 8fc1989e..54f1a10c 100644
--- a/share/man/just-profile.5.md
+++ b/share/man/just-profile.5.md
@@ -29,6 +29,11 @@ The metadata file contains the following information.
- For the key *`"time"`* the time of the invocation in seconds since
the epoch.
+- For the key *`"context"`* a map of the environment variables requested
+ to be included in the metadata file with the variable name as key and
+ the value of the variable as value (see *`"context variables"`* field
+ of the *`"invocation log"`* key in the **`just-mrrc`**(5) file).
+
Profile file
------------
diff --git a/src/other_tools/just_mr/cli.hpp b/src/other_tools/just_mr/cli.hpp
index d8ad0366..df952957 100644
--- a/src/other_tools/just_mr/cli.hpp
+++ b/src/other_tools/just_mr/cli.hpp
@@ -93,6 +93,7 @@ struct MultiRepoGcArguments {
struct InvocationLogArguments {
std::optional<std::filesystem::path> directory{std::nullopt};
std::optional<std::string> invocation_msg{std::nullopt};
+ std::vector<std::string> context_vars{};
std::optional<std::string> project_id{std::nullopt};
std::optional<std::string> metadata{std::nullopt};
std::optional<std::string> graph_file{std::nullopt};
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<std::filesystem::path> 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;
diff --git a/src/other_tools/just_mr/rc.cpp b/src/other_tools/just_mr/rc.cpp
index 51813dfb..7d7f6f5a 100644
--- a/src/other_tools/just_mr/rc.cpp
+++ b/src/other_tools/just_mr/rc.cpp
@@ -635,6 +635,16 @@ namespace {
if (msg->IsString()) {
clargs->invocation_log.invocation_msg = msg->String();
}
+ auto context_vars =
+ invocation_log->Get("context variables", Expression::none_t{});
+ if (context_vars->IsList()) {
+ for (auto const& env_var : context_vars->List()) {
+ if (env_var->IsString()) {
+ clargs->invocation_log.context_vars.emplace_back(
+ env_var->String());
+ }
+ }
+ }
}
}
// read config lookup order