Корневой URL-адрес vcs плана сборки Python teamcity

#python-3.x #teamcity

Вопрос:

Как я могу получить корневой URL-адрес VCS плана сборки teamcity на python? Я просмотрел документацию teamcity rest api и погуглил, если у кого — то уже была эта проблема, но, похоже, в Интернете нет подобных проблем.

Ответ №1:

 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)