diff --git a/dvc/env.py b/dvc/env.py index 72c5b8900..af36342dc 100644 --- a/dvc/env.py +++ b/dvc/env.py @@ -19,3 +19,4 @@ DVC_STUDIO_URL = "DVC_STUDIO_URL" DVC_SQLALCHEMY_ECHO = "DVC_SQLALCHEMY_ECHO" DVC_SYSTEM_CONFIG_DIR = "DVC_SYSTEM_CONFIG_DIR" DVC_UPDATER_ENDPOINT = "DVC_UPDATER_ENDPOINT" +DVC_STAGE = "DVC_STAGE" diff --git a/dvc/stage/run.py b/dvc/stage/run.py index 250c5c4d3..40369780e 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -39,7 +39,7 @@ def _enforce_cmd_list(cmd): def prepare_kwargs(stage, run_env=None): - from dvc.env import DVC_ROOT + from dvc.env import DVC_ROOT, DVC_STAGE kwargs = {"cwd": stage.wdir, "env": fix_env(None), "close_fds": True} @@ -48,6 +48,9 @@ def prepare_kwargs(stage, run_env=None): if DVC_ROOT not in kwargs["env"]: kwargs["env"][DVC_ROOT] = stage.repo.root_dir + # Create DVC_STAGE env variable for every command + kwargs["env"][DVC_STAGE] = stage.addressing + # NOTE: when you specify `shell=True`, `Popen` [1] will default to # `/bin/sh` on *nix and will add ["/bin/sh", "-c"] to your command. # But we actually want to run the same shell that we are running