def build_env_info(cls): try: repo_url = os.getenv(cls.CI_REPOSITORY_URL_ENV_VAR_NAME) repo_name = GitHelper.extractRepoName(repo_url) branch = os.getenv(cls.CI_COMMIT_BRANCH_ENV_VAR_NAME) if not branch: branch = os.getenv(cls.CI_COMMIT_REF_NAME_ENV_VAR_NAME) commit_hash = os.getenv(cls.CI_COMMIT_SHA_ENV_VAR_NAME) commit_message = os.getenv(cls.CI_COMMIT_MESSAGE_ENV_VAR_NAME) if not branch: branch = GitHelper.get_branch() if not commit_hash: commit_hash = GitHelper.get_commit_hash() if not commit_message: commit_message = GitHelper.get_commit_message() test_run_id = cls.get_test_run_id(repo_url, commit_hash) env_info = EnvironmentInfo(test_run_id, cls.ENVIRONMENT, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console("Gitlab Environment info: {}".format(env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console("Gitlab Unable to build environment info: {}".format(err)) LOGGER.error("Gitlab Unable to build environment info: {}".format(err)) pass return None
def build_env_info(cls): try: repo_url = "https://github.com/{}.git".format( os.getenv(cls.TRAVIS_REPO_SLUG_VAR_NAME)) repo_name = GitHelper.extractRepoName(repo_url) branch = os.getenv(cls.TRAVIS_PULL_REQUEST_BRANCH_ENV_VAR_NAME) commit_hash = os.getenv(cls.TRAVIS_COMMIT_ENV_VAR_NAME) commit_message = os.getenv(cls.TRAVIS_COMMIT_MESSAGE_ENV_VAR_NAME) if not branch: branch = GitHelper.get_branch() if not commit_hash: commit_hash = GitHelper.get_commit_hash() if not commit_message: commit_message = GitHelper.get_commit_message() test_run_id = cls.get_test_run_id(repo_url, commit_hash) env_info = EnvironmentInfo(test_run_id, cls.ENVIRONMENT, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console( "TravisCI Environment info: {}".format(env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console( "TravisCI Unable to build environment info: {}".format(err)) LOGGER.error( "TravisCI Unable to build environment info: {}".format(err)) pass return None
def build_env_info(cls): try: repo_url = os.getenv(cls.BITBUCKET_GIT_HTTP_ORIGIN_ENV_VAR_NAME) if not repo_url: repo_url = os.getenv(cls.BITBUCKET_GIT_SSH_ORIGIN_ENV_VAR_NAME) repo_name = GitHelper.extractRepoName(repo_url) branch = os.getenv(cls.BITBUCKET_BRANCH_ENV_VAR_NAME) commit_hash = os.getenv(cls.BITBUCKET_COMMIT_ENV_VAR_NAME) commit_message = GitHelper.get_commit_message() if not branch: branch = GitHelper.get_branch() if not commit_hash: commit_hash = GitHelper.get_commit_hash() test_run_id = cls.get_test_run_id(repo_url, commit_hash) env_info = EnvironmentInfo(test_run_id, cls.ENVIRONMENT, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console("Bitbucket Environment info: {}".format(env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console("Unable to build environment info: {}".format(err)) LOGGER.error("Unable to build environment info: {}".format(err)) pass return None
def stop(self): if self.t: try: if self.t.is_alive(): self.t.cancel() except Exception as e: utils.print_debug_message_to_console( "Error occured while canceling Status Reporter") pass finally: self.t = None
def build_env_info(cls): try: repo_url = GitHelper.get_repo_url() if not repo_url: return None repo_name = GitHelper.extractRepoName(repo_url) branch = GitHelper.get_branch() commit_hash = GitHelper.get_commit_hash() commit_message = GitHelper.get_commit_message() test_run_id = cls.get_test_run_id(repo_url, commit_hash) env_info = EnvironmentInfo(test_run_id, cls.ENVIRONMENT, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console("Git Environment info: {}".format( env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console( "Unable to build environment info: {}".format(err)) LOGGER.error("Unable to build environment info: {}".format(err)) pass return None
def build_env_info(cls): try: repo_url = os.getenv(cls.BUILD_REPOSITORY_URI_ENV_VAR_NAME) repo_name = os.getenv(cls.BUILD_REPOSITORY_NAME_ENV_VAR_NAME ) or GitHelper.extractRepoName(repo_url) branch = os.getenv(cls.BUILD_SOURCEBRANCHNAME_ENV_VAR_NAME) commit_hash = os.getenv(cls.BUILD_SOURCEVERSION_ENV_VAR_NAME) commit_message = os.getenv( cls.BUILD_SOURCEVERSIONMESSAGE_ENV_VAR_NAME ) or GitHelper.get_commit_message() repo_provider = os.getenv( cls.BUILD_REPOSITORY_PROVIDER_ENV_VAR_NAME) environment = cls.ENVIRONMENT + " - " + str( repo_provider) if repo_provider else cls.ENVIRONMENT if not branch: branch = GitHelper.get_branch() if not commit_hash: commit_hash = GitHelper.get_commit_hash() test_run_id = cls.get_test_run_id(repo_url, commit_hash, environment) env_info = EnvironmentInfo(test_run_id, environment, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console("Azure Environment info: {}".format( env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console( "Unable to build environment info: {}".format(err)) LOGGER.error("Unable to build environment info: {}".format(err)) pass return None
def build_env_info(cls): try: github_repo = os.getenv(cls.GITHUB_REPOSITORY_ENV_VAR_NAME) repo_url = "https://github.com/" + github_repo + ".git" repo_name = GitHelper.extractRepoName(github_repo) branch = os.getenv(cls.GITHUB_HEAD_REF_ENV_VAR_NAME) commit_hash = os.getenv(cls.GITHUB_SHA_ENV_VAR_NAME) commit_message = GitHelper.get_commit_message() github_event_path = os.getenv(cls.GITHUB_EVENT_PATH_ENV_VAR_NAME) if github_event_path: try: if os.path.isfile(github_event_path): with open(github_event_path) as f: try: event_data = json.loads(f.read()) from jsonpath_ng import jsonpath, parse jsonpath_expression = parse('$.pull_request.head.sha') match = jsonpath_expression.find(event_data) commit_hash = match[0].value except Exception as err: LOGGER.error("Github Unable to get json data from GitHub event file " + github_event_path); except Exception as err: print_debug_message_to_console("Unable to read GitHub event from file " + github_event_path) LOGGER.error("Github Unable to read GitHub event from file " + github_event_path) pass if not branch: branch = os.getenv(cls.GITHUB_REF_ENV_VAR_NAME) if branch and branch.startswith(cls.REFS_HEADS_PREFIX): branch = branch[len(cls.REFS_HEADS_PREFIX):] if not branch: branch = GitHelper.get_branch() if not commit_hash: commit_hash = GitHelper.get_commit_hash() test_run_id = cls.get_test_run_id(repo_url, commit_hash) env_info = EnvironmentInfo(test_run_id, cls.ENVIRONMENT, repo_url, repo_name, branch, commit_hash, commit_message) print_debug_message_to_console("Github Environment info: {}".format(env_info.to_json())) return env_info except Exception as err: print_debug_message_to_console("Github Unable to build environment info: {}".format(err)) LOGGER.error("Github Unable to build environment info: {}".format(err)) pass return None
def init(cls): """First check git provider, then iterate over ENVIRONMENTS_VARS dict. """ try: LOGGER.debug("Checking ci environments...") for key, clz in cls.ENVIRONMENTS_VARS.items(): LOGGER.debug("Current key, clz: {}, {}".format(key,clz)) if os.getenv(key): ei = clz.build_env_info() if ei: cls.environment_info = ei print_debug_message_to_console("Environment info: {}".format(cls.environment_info.to_json())) print_debug_message_to_console("Founded key and class: {}, {}".format(key, clz)) break if cls.environment_info == None: if GitHelper.get_repo_url(): print_debug_message_to_console("Couldn't find any ci envrionment! Trying .git file...") cls.environment_info = GitEnvironmentInfoProvider.build_env_info() print_debug_message_to_console("Environment info: {}".format(cls.environment_info.to_json())) else: print_debug_message_to_console("Couldn't find .git file!") except Exception as err: LOGGER.error("Environment Support environment_info could not set: {}".format(err)) cls.environment_info = None print_debug_message_to_console("environment_info is None!") pass