From e1ba73b3ff664159dde3e88bc9f2a098b4aed2e8 Mon Sep 17 00:00:00 2001 From: Christoph Alt <christoph.alt@fau.de> Date: Tue, 28 Feb 2023 13:08:48 +0100 Subject: [PATCH] added a function to extract gitlab ci variables --- cbutil/util.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cbutil/util.py b/cbutil/util.py index 2abe1ad..0e3dca1 100644 --- a/cbutil/util.py +++ b/cbutil/util.py @@ -55,6 +55,15 @@ def get_git_infos(repo_path: Union[Path, str], *, commit_key="commit", commit_ms return {commit_key: commit, commit_msg_key: commit_msg} +def get_git_infos_from_env(): + """ Extract commit, commit message, branch and project id from gitlab ci environment.""" + return {"commit": os.environ["CI_COMMIT_SHA"], + "commit_message": os.environ["CI_COMMIT_MESSAGE"], + "project_id": os.environ["CI_PROJECT_ID"], + "branch": os.environ["CI_COMMIT_BRANCH"], + } + + def file_time_to_sec(file_path) -> int: return int(os.path.getmtime(file_path)) -- GitLab