1

Using Team City 2017.1.1 (build 46654) I am trying to download artifacts using REST from Powershell on windows 10.

I am using this: https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-BuildArtifacts

but I still cannot get it to work. As an example I am trying download the info.txt artifact that I can access using my browser from the below URL:

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

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

I am doing the following from 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

But I get the error:

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

Based on below suggestion I have now tried:

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

But still get:

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

Any ideas?

u123
  • 15,603
  • 58
  • 186
  • 303
  • Have you seen [this](https://stackoverflow.com/questions/14242139/how-do-i-download-a-protected-file-using-powershell) answer? – grundic Jul 24 '17 at 12:12

2 Answers2

1

You can navigate recursively the artifacts of a given build:

http://mytc/httpAuth/app/rest/builds/id:294859/artifacts/ And use the node: children of the response.

Response might be:

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

Then, making the same request on: children.href, you may have another child. (ie: logs) When you reach the leaf item you want, instead of the children node, you will have a content node with the href you want to call.

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

Using the responses recursively will ensure the path of the artefact is correct, and the case. And will ensure the artefact is still available.

Didier Aupest
  • 3,227
  • 2
  • 23
  • 35
0

According to documentation, you need to change ID format and add /content/ in URL, replace

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

with

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

oryades
  • 364
  • 2
  • 5
  • I used the following URL https://teamcity/httpAuth/app/rest/builds/id:6590/artifacts/content/jar/arm.jar where jar/arm.jar is the artifact path you should also add '/content/' to url – oryades Jul 24 '17 at 13:15