6

This page states:

Bamboo's REST APIs provide the following capabilities:

  • Retrieve the artifacts for a build.

and here I see the documentation:

http://myhost.com:8085/bamboo/rest/api/latest/plan/{projectKey}-{buildKey}/artifact [GET]

When I try this link with the bamboo server I have, like:

https://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact

All I get is:

<artifacts expand="artifacts">
    <link href="http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact" rel="self"/>
    <artifacts start-index="0" max-result="0" size="0"/>
</artifacts>

So am I understanding the REST documentation completely wrong, or is there something wrong possibly with MY-PLAN and this link is supposed to provide me a war file as I expect?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

5 Answers5

4

I'm afraid you are misunderstanding the REST documentation; by "Retrieve the artifacts for a build", it means "retrieves information about the build artifacts defined for a given plan". As you have already seen, all you get back is an XML or JSON document describing the artifacts defined.

If you want to download an actual build artifact, you'll need to write a script that uses /rest/api/latest/result/ to get the latest successful build info and, from that, form an actual download link to the artifact.

RCross
  • 4,919
  • 4
  • 44
  • 42
  • This is where I get lost: "from that, form an actual download link to the artifact." Which parts of the results to use and how to put it all together to form a link? – niCk cAMel Mar 28 '18 at 12:05
  • The above gets you the specific -_ (e.g. from "buildResultKey"). The rest of the link you'll have to create yourself, but presumably you know the artifact name and path? – RCross Apr 03 '18 at 14:45
  • 1
    @RCross Unfortunately, that is useless for automation, unless you get an API URL to the artifact Log In won't work using the default URL(at least not in the current Bamboo's setup) a 301 is fired and the http parser is redirected to the bamboo login URL, EVEN if you pass login parameters in the headers. So all you get is the welcome log in prompt when you do a GET artifact-url. I will try and via rest and update this comment AND thanks for the interpretation about the meaning of the document. That saved me time. – eco May 07 '18 at 19:38
2

There are some issues related to your question: https://jira.atlassian.com/browse/BAM-11706 and BAM-16315 (which was deleted, because it contained customer details)

Bert Huijben
  • 19,525
  • 4
  • 57
  • 73
2

Here is the rest api documentation

https://docs.atlassian.com/atlassian-bamboo/REST/latest

Search for "/latest/result" documentation

http://myhost.com:8085/rest/api/latest/result/{projectKey}-{buildKey}-{buildNumber : ([0-9]+)|(latest)} [GET]

Example xml request

https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber?expand=artifacts

Example json request

https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber.json?expand=artifacts

Parse the artifacts node in the response. Each artifact should have an href property. Pass the href to curl to download the artifact. You will probably need to setup a Bamboo token for rest api authentication.

Example curl request

curl -X GET -H "Authorization: Bearer ${BAMBOO_TOKEN}" $ARTIFACT_HREF
oallauddin
  • 94
  • 5
0

Spent a long time looking for this answer. Ended up having to piece together information and here is what I got. As @oallauddin mentions above, you need to get the url of the file from the xml.

curl -H "Authorization: Bearer <KEY>" https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber?expand=artifacts

Alternative you can get it as json format

curl -H "Authorization: Bearer <KEY>" https://bamboo.server.com/rest/api/latest/result/projectKey-buildKey-buildNumber.json?expand=artifacts

I think where a lot of people are getting stuck is trying to use the Authorization header to download it after. BAM-20764 shows that this is NOT possible. You have to remove the header and use basic authentication with -u. Not both. Only the -u by itself.

curl -u username:password https://bamboo.server.com/browse/projectKey-build-Key-buildNumber/artifact/shared/<ARTIFACT_NAME>/<filename> --remote-name

The --remote-name/-O flag or --remote-header-name/-J is preferred here if you want to download the file with the default original name.

DSdavidDS
  • 153
  • 1
  • 2
  • 12
-2

You've the link

<link href="http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact" rel="self"/>

Using curl you can download the artifact.

curl --user ${username}:{password} http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact
  • This doesn't download the artifact; it simply downloads an XML/JSON document (XML by default) describing the artifacts available. – RCross Sep 21 '17 at 13:00
  • can you try like this `curl -O -L --user ${username}:{password} http://my.bamboo.server/rest/api/latest/plan/MY-PLAN/artifact` – Ravi Kishore Sep 22 '17 at 05:55
  • 1
    I can, but the result is exactly the same. It simply downloads some XML that shows the location/name of the artifact file. It does not download the artifact itself. – RCross Sep 25 '17 at 12:10