使用Team City 2017.1.1(build 46654( 我正在尝试从Windows 10上的Powershell使用REST下载工件。
我正在使用这个: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-BuildArtifacts
但我仍然无法让它工作。例如,我正在尝试下载可以使用浏览器从以下URL访问的信息.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.
有什么想法吗?
您可以递归地导航给定构建的工件:
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>
递归使用响应将确保工件的路径和大小写正确。并将确保工件仍然可用。
根据文档,您需要更改 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