使用 REST 从 Team City 下载工件

Download artifacts using REST from Team City

使用 Team City 2017.1.1(内部版本 46654)我正在尝试使用 windows 10 上的 Powershell 使用 REST 下载工件。

我正在使用这个: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-BuildArtifacts

但我仍然无法让它工作。例如,我正在尝试下载 info.txt 工件,我可以使用我的浏览器从下面 URL:

http://mytc/repository/download/MyBuildConfiguration/294859:id/output/logs/info.txt

基于: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-BuildArtifacts

我正在从 Powershell 执行以下操作:

$TeamCityUser = 'tcuser'
$TeamCityPassword = 'tcpass'
$securePassword = ConvertTo-SecureString $TeamCityPassword -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential($TeamCityUser, $securePassword)

$response = Invoke-WebRequest http://mytc/httpAuth/app/rest/builds/294859:id/artifacts/output/logs/info.txt -Credential $creds

但我得到错误:

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.

根据以下建议,我现在已经尝试过:

$response = Invoke-WebRequest http://mytc/httpAuth/app/rest/builds/id:294859/artifacts/output/logs/info.txt -Credential $creds

但还是得到:

Invoke-WebRequest : The remote server returned an error: (404) Not Found.

有什么想法吗?

根据文档,您需要更改 ID 格式并在 URL 中添加 /content/,替换

http://mytc/httpAuth/app/rest/builds/294859:id/artifacts/output/logs/info.txt

http://mytc/httpAuth/app/rest/builds/id:294859/artifacts/content/output/logs/info.txt

您可以递归地导航给定构建的工件:

http://mytc/httpAuth/app/rest/builds/id:294859/artifacts/ 并使用节点:children 的响应。

响应可能是:

<files count="1">
    <file name="output" modificationTime="20170724T160034+0200" href="/httpAuth/app/rest/builds/id:294859/artifacts/metadata/output">
        <children href="/httpAuth/app/rest/builds/id:294859/artifacts/children/output"/>
    </file>
</files>

然后,在 children.href 上提出相同的请求,您可能会有另一个 child。 (即:日志) 当您到达所需的叶项时,您将拥有一个包含您要调用的 href 的内容节点,而不是 children 节点。

<files count="1">
    <file name="info.txt" size="75435" modificationTime="20170724T160034+0200" href="/httpAuth/app/rest/builds/id:3906258/artifacts/metadata/output/logs/info.txt">
        <content href="/httpAuth/app/rest/builds/id:3906258/artifacts/content/output/logs/info.txt"/>
    </file>
</files>

递归地使用响应将确保人工制品的路径是正确的,并且大小写。并将确保人工制品仍然可用。