diff --git a/doc/source/commands/kiwi.rst b/doc/source/commands/kiwi.rst index 97d2c172..68f2578f 100644 --- a/doc/source/commands/kiwi.rst +++ b/doc/source/commands/kiwi.rst @@ -12,6 +12,7 @@ SYNOPSIS kiwi-ng -h | --help kiwi-ng [--profile=...] + [--setenv=...] [--temp-dir=] [--type=] [--logfile=] @@ -32,6 +33,7 @@ SYNOPSIS [--config=] result [...] kiwi-ng [--profile=...] + [--setenv=...] [--shared-cache-dir=] [--temp-dir=] [--target-arch=] @@ -143,6 +145,11 @@ GLOBAL OPTIONS XML description. The option can be specified multiple times to allow a combination of profiles. +--setenv= + + export environment variable and its value into the caller + environment. This option can be specified multiple times + --shared-cache-dir= Specify an alternative shared cache directory. The directory diff --git a/kiwi/cli.py b/kiwi/cli.py index 85086348..88898e0c 100644 --- a/kiwi/cli.py +++ b/kiwi/cli.py @@ -18,6 +18,7 @@ """ usage: kiwi-ng -h | --help kiwi-ng [--profile=...] + [--setenv=...] [--temp-dir=] [--target-arch=] [--type=] @@ -39,6 +40,7 @@ usage: kiwi-ng -h | --help [--config=] result [...] kiwi-ng [--profile=...] + [--setenv=...] [--shared-cache-dir=] [--temp-dir=] [--target-arch=] @@ -89,6 +91,9 @@ global options for services: image, system --profile= profile name, multiple profiles can be selected by passing this option multiple times + --setenv= + export environment variable and its value into the caller + environment. This option can be specified multiple times --shared-cache-dir= specify an alternative shared cache directory. The directory is shared via bind mount between the build host and image diff --git a/kiwi/tasks/base.py b/kiwi/tasks/base.py index 2a20efa8..21a1ee92 100644 --- a/kiwi/tasks/base.py +++ b/kiwi/tasks/base.py @@ -139,6 +139,12 @@ class CliTask: if self.global_args['--color-output']: log.set_color_format() + if self.global_args['--setenv']: + for setenv in self.global_args['--setenv']: + (variable, value) = self.attr_token(setenv) + log.info(f'--> Set Env[{variable}]="{value}"') + os.environ[format(variable)] = format(value) + # initialize runtime configuration # import RuntimeConfig late to make sure the logging setup applies from kiwi.runtime_config import RuntimeConfig diff --git a/test/unit/cli_test.py b/test/unit/cli_test.py index 1fadb1c3..d4484688 100644 --- a/test/unit/cli_test.py +++ b/test/unit/cli_test.py @@ -38,6 +38,7 @@ class TestCli: '--debug-run-scripts-in-screen': False, 'result': False, '--profile': [], + '--setenv': [], '--shared-cache-dir': '/var/cache/kiwi', '--temp-dir': '/var/tmp', '--target-arch': None, diff --git a/test/unit/tasks/base_test.py b/test/unit/tasks/base_test.py index fd34a19f..d73947c0 100644 --- a/test/unit/tasks/base_test.py +++ b/test/unit/tasks/base_test.py @@ -45,6 +45,7 @@ class TestCliTask: '--loglevel': None, '--color-output': True, '--profile': ['vmxFlavour'], + '--setenv': ['SOURCE_DATE_EPOCH=42'], '--type': None } mock_command_args.return_value = { @@ -78,6 +79,7 @@ class TestCliTask: '--loglevel': None, '--color-output': True, '--profile': ['vmxFlavour'], + '--setenv': [], '--type': None } self.task = CliTask() @@ -120,6 +122,7 @@ class TestCliTask: '--debug-run-scripts-in-screen': None, '--color-output': None, '--loglevel': '10', + '--setenv': [] } self.task = CliTask() mock_setLogLevel.assert_called_once_with(10) @@ -141,6 +144,7 @@ class TestCliTask: '--debug-run-scripts-in-screen': None, '--color-output': None, '--loglevel': 'bogus', + '--setenv': [] } self.task = CliTask() mock_setLogLevel.assert_called_once_with(20)