Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Is there a way to download the artifacts using API?

Ruban Siva March 17, 2015

I can access the artifacts for a build using:

<PlanKey>?buildstate=Successful&max-results=1&expand=results.result.artifacts

 

Result something like:

<artifacts start-index="0" max-result="2" size="2">
 <artifact>
<name>DACPAC</name>
<link href="http://<link>/artifact/shared/DACPAC/" rel="self"/>
<producerJobKey>REG-SQL-JOB1-10</producerJobKey>
<shared>true</shared>
<size>945514</size>
<prettySizeDescription>923 KB</prettySizeDescription>
</artifact>
</artifacts>

...

However, is it possible then to download the artifacts from the artifact link result without resorting to some sort of HTML scraping?

 

2 answers

1 vote
Ruban Siva March 18, 2015

OK I can see it will give the artifact but how can i use this to download all the artifacts associated with the plan?

In fact, how is this more useful than the original API url I was using in the question?

http://<URL>/rest/api/latest/result/<[projectKey]-[buildKey]>?buildstate=Successful&max-results=1&expand=results.result.artifacts

rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 18, 2015

Hello Ruban, "-- However, is it possible then to download the artifacts from the artifact link result without resorting to some sort of HTML scraping?" No, as mentioned earlier, it will be required to write a script to loop trough the results and download the artifacts. — Kind regards, Rafael P. Sperafico Atlassian Support

Yong Lee May 8, 2018

so what url to use for downloading the artifacts in the loop ?

0 votes
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 17, 2015

Hello Ruban,

Thank you for your question.

This is the REST API call associated to Artifacts /plan/{projectKey}-{buildKey}/artifact which will provide you with the following output:

&lt;artifacts expand="artifacts"&gt;
	&lt;link href="[bamboo-base-url]/rest/api/latest/plan/[projectKey]-[buildKey]/artifact" rel="self"/&gt;
	&lt;artifacts start-index="0" max-result="1" size="1"&gt;
		&lt;artifact&gt;
			&lt;id&gt;1081345&lt;/id&gt;
			&lt;name&gt;Greeting&lt;/name&gt;
			&lt;location/&gt;
			&lt;copyPattern&gt;*.txt&lt;/copyPattern&gt;
			&lt;shared&gt;true&lt;/shared&gt;
		&lt;/artifact&gt;
	&lt;/artifacts&gt;
&lt;/artifacts&gt;

It will be required to iterate through the result(s) above and use it to build the URL to download the files.

If you find this answer useful, I would kindly ask you to accept it so the same will be visible to others who might be facing the same issue you have inquired.

Thank you for your understanding.

Kind regards,
Rafael P. Sperafico
Atlassian Support

Peter Kahn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2015

Hi Rafael, this doesn't seem to work for me. http://builder:8085/rest/api/latest/plan/UTILS-SVNPERM/artifact?expand=artifacts should return my lone artifact definition but I get <artifacts expand="artifacts"><link href="http://builder:8085/rest/api/latest/plan/UTILS-SVNPERM/artifact"; rel="self"/><artifacts start-index="0" max-result="0" size="0"/></artifacts> Any clue what I'm missing?

Peter Kahn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2015

Oh, that ONLY works for share artifacts.Verified by looking at source and experimentation. Ok, I must share my artifacts to be able to use this call

Nima Rafiei March 28, 2018

"It will be required to iterate through the result(s) above and use it to build the URL to download the files."

 

Exactly how to use the results to build the URL? What should go where?

Yong Lee May 8, 2018

@Rafael Please provide more details on how the iteration is done as  there is no obvious info on what URL to use for subsequent download requests to get the artifacts, especially for plans that produce multiple artifacts

Like Kaushik Veluru likes this
Kaushik Veluru
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 5, 2019

Yong, were you able to figure out how to do the iteration or artifact results? 

jeffrey monaco February 16, 2021

@Kaushik Veluru Do you know how the URL should be put together to download the artifact? I have no problem getting the information and parsing it. I am just not sure how the URL is formatted

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2021

The REST api ended up not helping me, because most of the interesting artifacts I needed to grab weren't individually named but shared via expressions, e.g. *.deb. As far as I can tell in Feb 2021, the REST API will not detail out individual artifacts that were gathered via an expression, so I had to resort to a small amount of html web scraping. 

In Python 3.8, here's my grand html scraping class:

class ParseBambooHTML(HTMLParser):
artifacts_list = list()

def handle_starttag(self, tag, attrs):
if tag == 'a':
for name, value in attrs:
if name == 'href':
self.artifacts_list.append(value)

My entire flow is to use requests to do a GET on the url that you can browse to in a normal browser, e.g. 

https://bamboo/artifact/PROJ-ECT/shared/build-latest/example-folder/

(I'm using dummy values there, substitute your bamboo url, project key, and folder, but importantly it has to be a url that shows the files you want to parse/download)

In the example below I'll search for a hypothetical file with 'xxxyyy' in the name, but the version changes each build:  (this is massively cut down, but it gives you the gist) 

r = session.get(url, timeout=30)
parser = ParseBambooHTML()
parser.feed(r.text)
parser.close()

for line in parser.artifacts_list:
if 'xxxyyy' in line: # '/artifact/PROJ-ECT/shared/build-latest/example-folder/xxxyyy_21.2.17.123.deb'
artifact_uri = line
artifact_filename = artifact_uri.split('/')[-1] # 'xxxyyy_21.2.17.123.deb'
break

With the uri + the file name, you can retrieve the file easily enough now.

Hopefully this added something to the discussion. 

-Kelly

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events