classAzureProvider_2.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. def init(self):
  2. globals.printdebug(f"DEBUG: Initializing Azure DevOps SCM Provider")
  3. self.azure_base_url = os.getenv('SYSTEM_COLLECTIONURI')
  4. self.azure_api_token = os.getenv('SYSTEM_ACCESSTOKEN')
  5. if not self.azure_api_token:
  6. self.azure_api_token = os.getenv('AZURE_API_TOKEN')
  7. self.azure_pull_request_id = os.getenv('SYSTEM_PULLREQUEST_PULLREQUESTID')
  8. self.azure_project = os.getenv('SYSTEM_TEAMPROJECT')
  9. self.azure_project_id = os.getenv('SYSTEM_TEAMPROJECTID')
  10. self.azure_repo_id = os.getenv('BUILD_REPOSITORY_ID')
  11. self.azure_build_source_branch = os.getenv('BUILD_SOURCEBRANCH')
  12. globals.printdebug(f'DEBUG: Azure DevOps base_url={self.azure_base_url} api_token={self.azure_api_token} '
  13. f'pull_request_id={self.azure_pull_request_id} project={self.azure_project} '
  14. f'project_id={self.azure_project_id} repo_id={self.azure_repo_id}')
  15. if not self.azure_base_url or not self.azure_project or not self.azure_repo_id or not self.azure_api_token \
  16. or not self.azure_project_id:
  17. print(f'BD-Scan-Action: ERROR: Azure DevOps requires that SYSTEM_COLLECTIONURI, SYSTEM_TEAMPROJECT,'
  18. 'SYSTEM_TEAMPROJECTID, SYSTEM_ACCESSTOKEN or AZURE_API_TOKEN, and BUILD_REPOSITORY_ID be set.')
  19. sys.exit(1)
  20. if globals.args.comment_on_pr and not self.azure_pull_request_id:
  21. print(f'BD-Scan-Action: ERROR: Azure DevOps requires that SYSTEM_PULLREQUEST_PULLREQUESTID be set'
  22. 'when operating on a pull request')
  23. sys.exit(1)
  24. if globals.args.fix_pr and not self.azure_build_source_branch:
  25. print(f'BD-Scan-Action: ERROR: Azure DevOps requires that BUILD_SOURCEBRANCH be set'
  26. 'when operating on a pull request')
  27. sys.exit(1)
  28. self.azure_credentials = BasicAuthentication('', self.azure_api_token)
  29. self.azure_connection = Connection(base_url=self.azure_base_url, creds=self.azure_credentials)
  30. # Get a client (the "core" client provides access to projects, teams, etc)
  31. self.azure_git_client = self.azure_connection.clients.get_git_client()
  32. return True