def init(self): globals.printdebug(f"DEBUG: Initializing Azure DevOps SCM Provider") self.azure_base_url = os.getenv('SYSTEM_COLLECTIONURI') self.azure_api_token = os.getenv('SYSTEM_ACCESSTOKEN') if not self.azure_api_token: self.azure_api_token = os.getenv('AZURE_API_TOKEN') self.azure_pull_request_id = os.getenv('SYSTEM_PULLREQUEST_PULLREQUESTID') self.azure_project = os.getenv('SYSTEM_TEAMPROJECT') self.azure_project_id = os.getenv('SYSTEM_TEAMPROJECTID') self.azure_repo_id = os.getenv('BUILD_REPOSITORY_ID') self.azure_build_source_branch = os.getenv('BUILD_SOURCEBRANCH') globals.printdebug(f'DEBUG: Azure DevOps base_url={self.azure_base_url} api_token={self.azure_api_token} ' f'pull_request_id={self.azure_pull_request_id} project={self.azure_project} ' f'project_id={self.azure_project_id} repo_id={self.azure_repo_id}') if not self.azure_base_url or not self.azure_project or not self.azure_repo_id or not self.azure_api_token \ or not self.azure_project_id: print(f'BD-Scan-Action: ERROR: Azure DevOps requires that SYSTEM_COLLECTIONURI, SYSTEM_TEAMPROJECT,' 'SYSTEM_TEAMPROJECTID, SYSTEM_ACCESSTOKEN or AZURE_API_TOKEN, and BUILD_REPOSITORY_ID be set.') sys.exit(1) if globals.args.comment_on_pr and not self.azure_pull_request_id: print(f'BD-Scan-Action: ERROR: Azure DevOps requires that SYSTEM_PULLREQUEST_PULLREQUESTID be set' 'when operating on a pull request') sys.exit(1) if globals.args.fix_pr and not self.azure_build_source_branch: print(f'BD-Scan-Action: ERROR: Azure DevOps requires that BUILD_SOURCEBRANCH be set' 'when operating on a pull request') sys.exit(1) self.azure_credentials = BasicAuthentication('', self.azure_api_token) self.azure_connection = Connection(base_url=self.azure_base_url, creds=self.azure_credentials) # Get a client (the "core" client provides access to projects, teams, etc) self.azure_git_client = self.azure_connection.clients.get_git_client() return True