diff --git a/tests/framework/properties.py b/tests/framework/properties.py index d934e5d62962..036d3743b424 100644 --- a/tests/framework/properties.py +++ b/tests/framework/properties.py @@ -72,13 +72,19 @@ def __init__(self): self.os = get_os_version() self.host_os = get_host_os() self.libc_ver = "-".join(platform.libc_ver()) - self.git_commit_id = run_cmd("git rev-parse HEAD") - self.git_branch = run_cmd("git show -s --pretty=%D HEAD") - self.git_origin_url = run_cmd("git config --get remote.origin.url") self.rust_version = run_cmd("rustc --version |awk '{print $2}'") self.buildkite_pipeline_slug = os.environ.get("BUILDKITE_PIPELINE_SLUG") self.buildkite_build_number = os.environ.get("BUILDKITE_BUILD_NUMBER") + if self._in_git_repo(): + self.git_commit_id = run_cmd("git rev-parse HEAD") + self.git_branch = run_cmd("git show -s --pretty=%D HEAD") + self.git_origin_url = run_cmd("git config --get remote.origin.url") + else: + self.git_commit_id = None + self.git_branch = None + self.git_origin_url = None + self.environment = self._detect_environment() if self.is_ec2: self.instance = imdsv2_get("/meta-data/instance-type") @@ -105,6 +111,12 @@ def _detect_environment(self): except Exception: return "local" + def _in_git_repo(self): + try: + run_cmd("git rev-parse --show-toplevel") + except subprocess.CalledProcessError: + return False + return True + global_props = GlobalProps() -# TBD could do a props fixture for tests to use...