如何在 python 上获取 teamcity 构建计划的 VCS 根 URL?我查看了 teamcity rest api 文档,如果有人已经遇到过这个问题,我会用谷歌搜索 - 但似乎互联网上没有类似的问题。
答案 0 :(得分:0)
from dohq_teamcity import TeamCity
from dohq_teamcity.configuration import Configuration
from settings.config import settings
config = Configuration()
config.api_key = {'token': settings.TEAMCITY_TOKEN}
config.api_key_prefix = {'token': 'Bearer'}
config.active_api_key = 'token'
tc = TeamCity(settings.TEAMCITY_URL, auth_settings=["Token"], configuration=config)
vcs_roots_locators = [x.locator_id for x in tc.vcs_root.get_roots().data]
def get_vcs_roots_vcs_url(tc: TeamCity, locator: str) -> str:
vcs_root = tc.vcs_root.get_root(vcs_root_locator=locator)
return [y for y in vcs_root.properties.data if y.name == 'url'][0].value
vcs_roots_urls = [get_vcs_roots_vcs_url(tc, x) for x in vcs_roots_locators]
print(vcs_roots_urls)