Python teamcity 构建计划 vcs root url

时间:2021-04-21 07:03:12

标签: python-3.x teamcity

如何在 python 上获取 teamcity 构建计划的 VCS 根 URL?我查看了 teamcity rest api 文档,如果有人已经遇到过这个问题,我会用谷歌搜索 - 但似乎互联网上没有类似的问题。

1 个答案:

答案 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)


相关问题