【问题标题】:Download artifacts using REST from Team City使用 REST 从 Team City 下载工件
【发布时间】:2017-07-24 22:11:40
【问题描述】:

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

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

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

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.

有什么想法吗?

【问题讨论】:

  • 你看到this的答案了吗?

标签: rest powershell teamcity powershell-4.0


【解决方案1】:

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

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 上提出相同的请求,您可能会有另一个孩子。 (即:日志) 当您到达所需的叶子项目时,您将拥有一个内容节点,而不是子节点,并且您要调用的 href。

<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>

递归使用响应将确保工件的路径是正确的,并且案例。并且将确保文物仍然可用。

【讨论】:

    【解决方案2】:

    【讨论】:

    猜你喜欢
    • 2013-04-09
    • 1970-01-01
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-25
    • 2013-01-11
    • 1970-01-01
    相关资源
    最近更新 更多